Edit page in Livemark
(2022-11-24 15:10)

Json Format

Frictionless supports parsing YAML tables.

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.yaml', 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.yaml', type='table')
print(target)
print(target.to_view())
{'name': 'table-output',
 'type': 'table',
 'path': 'table-output.yaml',
 'scheme': 'file',
 'format': 'yaml',
 'mediatype': 'text/yaml'}
+----+-----------+
| 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.YamlControl(keyed=True)
resource = Resource(path='table.keyed.yaml', type='table', control=control)
pprint(resource.read_rows())
[{'id': 1, 'name': 'english'}, {'id': 2, 'name': '中国人'}]

Reference

formats.YamlControl (class)

formats.YamlControl (class)

Yaml 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.yamlControl.keys (property)

Specifies the keys/columns to read from the resource. For example: keys=["id","name"].

Signature

Optional[List[str]]

formats.yamlControl.keyed (property)

If set to True, It returns the data as key:value pair. Default value is False.

Signature

bool

formats.yamlControl.property (property)

This property specifies the path to the attribute in a json file, it it has nested fields.

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.