galactic.io.data.json#

galactic.io.data.json module

Defines the data reader for JSON files.

Class


class JSONDataReader#

Bases: object

JSON Data reader.

Example

>>> from pprint import pprint
>>> from galactic.io.data.json import JSONDataReader
>>> reader = JSONDataReader()
>>> import io
>>> text = '''
... {
... "#1": {
...     "firstname": "Évariste",
...     "name": "Galois"
...   },
... "#2": {
...     "firstname": "Rudolf",
...     "name": "Wille"
...   }
... }
... '''
>>> dataset = reader.read(io.StringIO(text))
>>> pprint(dataset)
{'#1': {'firstname': 'Évariste', 'name': 'Galois'},
 '#2': {'firstname': 'Rudolf', 'name': 'Wille'}}
read(data_file)#

Read a JSON data file.

Parameters:

data_file (TextIO) – A readable text file

Returns:

The dataset read from the file

Return type:

dict[str, None | bool | int | float | str | list[JSONValue] | dict[str, JSONValue]] | list[None | bool | int | float | str | list[JSONValue] | dict[str, JSONValue]]

extensions()#

Return an iterator over the supported file extensions.

Returns:

An iterator over the supported file extensions

Return type:

Iterator[str]

register()#

Register an instance of the JSON data reader.

Return type:

None