As others have pointed out if you're targeting Emacs 23 or even 22 you don't have a “package” but only a library. “Packages” don't exist in Emacs prior to Emacs 24 when the package manager was added.
Bundling with a library
Since there's no standard way to install libraries before packages you can bundle json.el into whatever you give to your users—some kind of an archive I presume. They'll have to install it manually anyway and can thus pick whatever files they need: Just your library for Emacs 24/25 users, your library + json.el for those with older versions.
As long as you document this it won't cause any trouble.
Bundling with a package
Do absolutely not bundle it.
However, if you build a proper package for Emacs 24 and upwards you must not include
The package manager will happily install your bundled copy of
json.el along with your actual library. Since packages come first in
load-path your bundled copy of
json.el will now override the built-in one, causing all sorts of trouble for packages that expect a more recent version of
The way to go (in my opinion)
Create two distributions of your package:
- A proper Emacs package for Emacs 24 and above, e.g. a TAR with the corresponding package metadata. You could even host a small package repository with your package to distribute updates to Emacs 24 users automatically.
- A TAR file with your library and
json.el, but without package metadata for users of older Emacs versions.
The only thing that you need to watch out for is when users of older Emacs versions update to Emacs 24. In this case they'll have to manually remove the previous installation of your library along with
json.el and install the proper Emacs 24 package again.
If you don't want to maintain two different distributions you can bundle
json.el, but under a different name, e.g.
my-library-json-compat.el. With a different name your bundle copy of
json.el will never override the built-in one.
Since the functions and symbols in the bundled copy would still conflict with the built-in one, you must take care not to load your bundled copy when the real
json.el is available, but this is easy:
(unless (require 'json nil 'no-error)
(require 'json "my-library-json-compat"))
Emacs will try to load
json.el, and failing that fall back to your bundled copy under a different name.
The real way to go (in my opinion)
Tell your users to update to Emacs 24. The last release of Emacs 22 is eight(!) years ago, the last release of Emacs 23 still four years ago. Both versions are outdated and lack a lot of features, and many packages (e.g. Magit) only support Emacs 24 nowadays. Emacs 22/23 are a dead end and there's no way forward from them.
Updating to Emacs 24 is easy enough: Most modern Linux distribution include at least Emacs 24.1 in their package repositories. For OS X pre-built App bundles are available, and the latest stable Emacs 24 is included in the popular OS X package manager Homebrew.