Skip to main content

Tabular-JSON: A superset of JSON adding CSV-like tables

Project description

Tabular-JSON Python

This is a Python implementation of Tabular-JSON, a superset of JSON adding CSV-like tables.

Install

Install via PyPi: https://pypi.org/project/tabularjson/

pip install tabularjson

Use

from tabularjson import parse, stringify, StringifyOptions

text = """{
    "id": 1,
    "name": "Brandon",
    "friends": ---
    "id", "name"
        2,    "Joe"
        3,    "Sarah"
    ---
}
"""

data = parse(text)
print(data)
# {
#     'id': 1,
#     'name': 'Brandon',
#     'friends': [
#         {'id': 2, 'name': 'Joe'},
#         {'id': 3, 'name': 'Sarah'}
#     ]
# }

data["friends"].append({"id": 4, "name": "Alan"})

options: StringifyOptions = {"indentation": 4, "trailingCommas": False}
updatedText = stringify(data, options)
print(updatedText)
# {
#     "id": 1,
#     "name": "Brandon",
#     "friends": ---
#         "id", "name"
#         2,    "Joe"
#         3,    "Sarah"
#         4,    "Alan"
#     ---
# }

API

parse

Parse a string containing Tabular-JSON data into JSON.

Syntax:

data = parse(text)

Where:

  • text is a string containing Tabular-JSON data
  • data is the parsed data, returned by the function

Example:

from tabularjson import parse

text = """{
    "id": 1,
    "name": "Brandon",
    "friends": ---
    "id", "name"
        2,    "Joe"
        3,    "Sarah"
    ---
}
"""

data = parse(text)
print(data)
# {
#     'id': 1,
#     'name': 'Brandon',
#     'friends': [
#         {'id': 2, 'name': 'Joe'},
#         {'id': 3, 'name': 'Sarah'}
#     ]
# }

stringify

Stringify data into a string containing Tabular-JSON.

Syntax:

text = stringify(data, options)

Where:

  • data is a JSON object or array
  • options is an optional object which can have the following properties:
    • indentation: int | str | None an integer specifying the number of spaces in the indentation, or a string containing the indentation itself, like "\t" to get tab indentation. When None (default), the output will not be indented.
    • trailingCommas: bool when true, the output will contain trailing commas after the last item in an array and the last key/value pair in an object. False by default.
  • text is a string containing Tabular-JSON data, returned by the function

Example:

from tabularjson import stringify, StringifyOptions

data = {
    'id': 1,
    'name': 'Brandon',
    'friends': [
        {'id': 2, 'name': 'Joe'},
        {'id': 3, 'name': 'Sarah'}
    ]
}

options: StringifyOptions = {"indentation": 4, "trailingCommas": False}
text = stringify(data, options)

print(text)
# {
#     "id": 1,
#     "name": "Brandon",
#     "friends": ---
#         "id", "name"
#         2,    "Joe"
#         3,    "Sarah"
#     ---
# }

License

Released under the ISC license.

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

tabularjson-1.0.2.tar.gz (11.5 kB view details)

Uploaded Source

Built Distribution

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

tabularjson-1.0.2-py3-none-any.whl (10.5 kB view details)

Uploaded Python 3

File details

Details for the file tabularjson-1.0.2.tar.gz.

File metadata

  • Download URL: tabularjson-1.0.2.tar.gz
  • Upload date:
  • Size: 11.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.10

File hashes

Hashes for tabularjson-1.0.2.tar.gz
Algorithm Hash digest
SHA256 107e66ec08f34326e3a66b0b5e6b7fa25671616dab4ed80a8cb127a8cda95565
MD5 fea31630de145c0d5701e01a2b70f2c4
BLAKE2b-256 9557bd07912559e56c2d6188613d6b36ed28e6a808f1ae946e1ada0e3b26640a

See more details on using hashes here.

File details

Details for the file tabularjson-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: tabularjson-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 10.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.10

File hashes

Hashes for tabularjson-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 9d81ee7f0331ee5e6c589171d8be2a15ec141201ca056f88fd6836bc0f1662bf
MD5 969d42013b9f19c32d4e0930808cbb70
BLAKE2b-256 8d011351443dddbcd89fb61ed2837bb801c8e5739b798e93c41b04e4dc3058ba

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