Skip to main content

Calculate the source map for a JSON document.

Project description

JsonSourceMap

Calculate JSON Pointers to each value within a JSON document along with the line, column and character position for the start and end of that value. For more information see: https://github.com/open-alchemy/json-source-map/wiki.

For example:

python -m pip install json_source_map
from json_source_map import calculate


print(calculate('{"foo": "bar"}'))

The above prints:

{
    '': Entry(
        value_start=Location(line=0, column=0, position=0),
        value_end=Location(line=0, column=14, position=14),
        key_start=None,
        key_end=None,
    ),
    '/foo': Entry(
        value_start=Location(line=0, column=8, position=8),
        value_end=Location(line=0, column=13, position=13),
        key_start=Location(line=0, column=1, position=1),
        key_end=Location(line=0, column=6, position=6),
    ),
}

Where:

  • each key in the dictionary is a JSON path to an item,
  • each value in the dictionarty contains the mapping of the item at the JSON path which have the following properties:
    • value_start is the start of the value,
    • value_end is the end of the value,
    • key_start is the start of the key (which is None at the root level and for array items),
    • key_end is the end of the key (which is None at the root level and for array items) and
  • each of the above have the following properties:
    • line is the zero-indexed line position,
    • column is the zero-indexed column position and
    • position is the zero-indexed character position in the string (independent of the line and column).

The following features have been implemented:

  • support for primitive types (strings, numbers, booleans and null),
  • support for structural types (array and object) and
  • support for space, tab, carriage and return whitespace.

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_source_map-1.0.5.tar.gz (6.7 kB view details)

Uploaded Source

Built Distribution

json_source_map-1.0.5-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

Details for the file json_source_map-1.0.5.tar.gz.

File metadata

  • Download URL: json_source_map-1.0.5.tar.gz
  • Upload date:
  • Size: 6.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.16

File hashes

Hashes for json_source_map-1.0.5.tar.gz
Algorithm Hash digest
SHA256 de99103c0637707368eb888d7aaa82bad1e21dbe2d21813998caabaa7c2e52f9
MD5 a7fc7f346e10edfea1c01f92904e5b97
BLAKE2b-256 e6f0560df0f36ad3e6c1e9b2a077a297df2c4dc4a2c427580d1995782aff67d1

See more details on using hashes here.

File details

Details for the file json_source_map-1.0.5-py3-none-any.whl.

File metadata

File hashes

Hashes for json_source_map-1.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 c8ddb8db76dc238fce485abb548e5c7fc2b44d5ae8efb766e90e7c15840afaca
MD5 8aceed45ba1e43dc176f615468bbc248
BLAKE2b-256 2f5cbdddb48cf521428117bd1338c531c0027f1c32beba23c89f9713229fe17c

See more details on using hashes here.

Supported by

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