Skip to main content

javascript-data-files

Work with JSON which is stored as a value in a JavaScript file

This is a collection of Python functions for manipulating JavaScript “data files” – that is, JavaScript files that define a single variable with a JSON value.

This is an example of a JavaScript data file:

const shape = { "sides": 5, "colour": "red" };

Think of this module as the JSON module, but for JavaScript files.

These data files are meant to be both human- and machine-readable.

Usage

If you install javascript-data-files:

If you install javascript-data-files[typed]:

Installation

You have two options:

  1. Copy the file src/javascript folder into your project. You probably want to copy the tests as well.

  2. Install the package using pip:

    $ pip install javascript-data-files

Why not use JSON files?

If you’ve opening an HTML file from disk, you can load data from a local JavaScript file, for example:

<script src="file://users/alexwlchan/repos/javascript-data-files/data.js"></script>

This is the only way to load data from an external file from an HTML file you’ve opened locally – you can’t do this with a JSON file, for example.

I have a lot of HTML files and local sites I build with an HTML viewer and metadata in a JavaScript file. The convenience of this approach outweighs the mild annoyance of having to store data in JavaScript, not JSON.

Development

If you want to make changes to the library, there are instructions in CONTRIBUTING.md.

License

MIT.