Edit page in Livemark
(2022-09-19 18:33)

Json Format

Frictionless supports parsing JSON tables (JSON and JSONL/NDJSON).

pip install frictionless[json]
pip install 'frictionless[json]' # for zsh shell

Reading Data

We use the path argument to ensure that it will not be guessed to be a metadata file

You can read this format using Package/Resource, for example:

from pprint import pprint
from frictionless import Resource

resource = Resource(path='table.json', type='table')
pprint(resource.read_rows())
[{'id': 1, 'name': 'english'}, {'id': 2, 'name': '中国人'}]

Writing Data

The same is actual for writing:

from frictionless import Resource

source = Resource(data=[['id', 'name'], [1, 'english'], [2, 'german']])
target = source.write(path='table-output.json', type='table')
print(target)
print(target.to_view())
{'name': 'table-output',
 'type': 'table',
 'path': 'table-output.json',
 'scheme': 'file',
 'format': 'json',
 'mediatype': 'text/json'}
+----+-----------+
| id | name      |
+====+===========+
|  1 | 'english' |
+----+-----------+
|  2 | 'german'  |
+----+-----------+

Configuration

There is a dialect to configure how Frictionless read and write files in this format. For example:

from pprint import pprint
from frictionless import Resource, formats

control=formats.JsonControl(keyed=True)
resource = Resource(path='table.keyed.json', type='table', control=control)
pprint(resource.read_rows())
[{'id': 1, 'name': 'english'}, {'id': 2, 'name': '中国人'}]

Reference

formats.JsonControl (class)

formats.JsonControl (class)

Json control representation

Signature

(*, title: Optional[str] = None, description: Optional[str] = None, keys: Optional[List[str]] = None, keyed: bool = False, property: Optional[str] = None) -> None

Parameters

  • title (Optional[str])
  • description (Optional[str])
  • keys (Optional[List[str]])
  • keyed (bool)
  • property (Optional[str])

formats.jsonControl.keys (property)

NOTE: add docs

Signature

Optional[List[str]]

formats.jsonControl.keyed (property)

NOTE: add docs

Signature

bool

formats.jsonControl.property (property)

NOTE: add docs

Signature

Optional[str]

It's a beta version of Frictionless Framework (v5). Read Frictionless Framework (v4) docs for a version that is currently installed by default by pip.