Skip to main content

A JSON5 parser that, among other features, supports round-trip preservation of comments

Project description

# json-five

JSON5 for Python

## Installation

` pip install json-five `

## Usage

NOTE: the import name is different from the install name (sorry, many were taken already)

`python >>> import json5 >>> json_text = """{ // This is a JSON5 comment "foo": "bar" /* this is a JSON5 block comment that can span lines /* "bacon": "eggs" } """ >>> json5.loads(json_text) {"foo": "bar", "bacon": "eggs"} `

## Project goals

  • support a similar interface to the json module with support for JSON5 sources

  • support round-trip preservation of comments

## Status/milestones

This project is in very early stages of development. The following are some milestones that hopefully will be able to be marked as done as development progresses.

  • [x] parse json5 to Python (ignoring comments) - [x] line comments - [x] block comments - [x] numeric literals - [x] trailing commas for arrays and objects - [x] line continuations - [x] ecma identifiers as object keys - [x] leading plus for numbers - [x] single quoted strings - [x] escape characters in strings

  • [ ] dump python to JSON (no comment support) - [x] indent style (that matches json) - [ ] style options (quotes, trailing commas, etc) - [ ] helper classes for dumping types as other literals (hexadecimal numbers, identifiers, etc) - [x] load/loads to support similar options to json (e.g. object_hook, parse_x, etc) - [ ] dump/dumps to support similar options to json module (e.g. hooks, ensure_ascii, etc) - [ ] string escapes according to quote style

  • [ ] support manipulation of json model (e.g. to add/edit comments)

  • [ ] dump json model with comments

  • [ ] preserve comments when loading json5 (round-trip support)

  • [ ] Optimize with a C/Cython version

## How fast is it?

It’s nowhere close to the C-optimized json stdlib module. We may get closer to that benchmark if/when we rewrite parts with Cython.

In my own limited testing, as of v0.0.2, this module is about 10-450x slower than the stdlib C-optimized json and about 10-50x slower than the stdlib pure python version of json.

I expect this to slow down marginally when round-trip comment preservation is implemented.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

json-five-0.0.3.tar.gz (12.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

json_five-0.0.3-py3-none-any.whl (13.4 kB view details)

Uploaded Python 3

File details

Details for the file json-five-0.0.3.tar.gz.

File metadata

  • Download URL: json-five-0.0.3.tar.gz
  • Upload date:
  • Size: 12.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.2

File hashes

Hashes for json-five-0.0.3.tar.gz
Algorithm Hash digest
SHA256 6a693fb5690154fb0d3fddd1be081c08a338fb820add4600e8e5892163f2ba66
MD5 839716835ea1265ad0180351d585cd42
BLAKE2b-256 5913860a246c66a3d60acc7ae5372518e488a4224156b905d1f7446e74a40d55

See more details on using hashes here.

File details

Details for the file json_five-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: json_five-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 13.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.2

File hashes

Hashes for json_five-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 4028cb20cbea2c23a10bb547e1e68143256a96b85450395147ae9f0719fc30bd
MD5 683007bce5d63a79216b589eda271aa4
BLAKE2b-256 c2e99414b2082b88fbabeaf5d0de16612492e1de11c8f9cbddc804c9cee416e2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page