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:
textis a string containing Tabular-JSON datadatais 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:
datais a JSON object or arrayoptionsis an optional object which can have the following properties:indentation: int | str | Nonean integer specifying the number of spaces in the indentation, or a string containing the indentation itself, like"\t"to get tab indentation. WhenNone(default), the output will not be indented.trailingCommas: boolwhen true, the output will contain trailing commas after the last item in an array and the last key/value pair in an object.Falseby default.
textis 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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
107e66ec08f34326e3a66b0b5e6b7fa25671616dab4ed80a8cb127a8cda95565
|
|
| MD5 |
fea31630de145c0d5701e01a2b70f2c4
|
|
| BLAKE2b-256 |
9557bd07912559e56c2d6188613d6b36ed28e6a808f1ae946e1ada0e3b26640a
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9d81ee7f0331ee5e6c589171d8be2a15ec141201ca056f88fd6836bc0f1662bf
|
|
| MD5 |
969d42013b9f19c32d4e0930808cbb70
|
|
| BLAKE2b-256 |
8d011351443dddbcd89fb61ed2837bb801c8e5739b798e93c41b04e4dc3058ba
|