5.5. yapydata.datatree.synjson

The JSON access in compliance to RFC-7159 [RFC7159].

5.5.1. Module

The YapyData.json module provides JSON access in compliance to RFC-7159 [RFC7159].

Sources: yapydata/datatree/synjson.py

5.5.2. Functions

5.5.2.1. grow_branch

yapydata.datatree.synjson.grow_branch(*subpath, **kargs)[source]

Creates a new branch including the assigned value to the last node. The node types are defined by the types of the subpath entries.

Supports a single linear branch only, no sub-branching.

The created path is validated for permitted types. The derived types such as JSON have to support their own branch method. Thus provided as a static method.

Parameters
  • subpath – Variable list/tuple of path keys and indexes.

  • kargs

    value:

    Value to be assigned to the final node.

Returns

A created branch.

Raises

pass-through

5.5.2.2. readout_data

yapydata.datatree.synjson.readout_data(xval, **kargs)[source]

For API call-compliance with other syntaxes. Returns here the input tree only.

Parameters

xval – The input tree from the DataTreeJSON - which is the result from json.load().

Returns

The returns here the input xval.

Raises

pass-through

5.5.3. DataTreeJSON

class yapydata.datatree.synjson.DataTreeJSON(data=None, **kargs)[source]

Provides JSON RFC-7159 compliant in-memory data trees.

5.5.3.1. __init__

DataTreeJSON.__init__(data=None, **kargs)[source]
Parameters

data

A JSON compliant in-memory data tree in accordance to RFC-7159:

json-value := (
      object | array
    | number
    | string
    | false  | true
    | null
)

The equivalent Python types are:

data := <RFC-7159-type-for-json>

RFC-7159-type-for-json := (
      dict | list            # see: object, array
    | int  | float           # see: number
    | str                    # see: unicode / for Python: ISSTR = (str(3) | unicode(2))
    | None | True  | False   # see: null, true, false
)

The initial data defines the permitted type of the first item within the subpath of the spanned data tree.

Thus atomic data types define a single node data tree only - new in RFC-7159.

Returns

None / initialized object

Raises

5.5.3.2. isvalid_top

static DataTreeJSON.isvalid_top(value, **kargs)[source]

Validate conformance of top-node to RFC-7159.

5.5.3.3. __setattr__

DataTreeJSON.__setattr__(name, value)[source]

Validates types of own data attributes.

Parameters
  • name

    Name of the attribute. Following are reserved and treated special:

    • type: str - ‘data’ The value is treated as the replacement of the internal data attribute. Replaces or creates the complete data of teh current instance.

  • value – The value of the attribute. This by default superposes present values by replacement. Non-present are created.

Returns:

Raises

YapyDataDataTreeError

5.5.3.4. create

DataTreeJSON.create(*subpath, **kargs)[source]

Adds constraints in accordance to RFC-7159.

5.5.3.5. import_data

DataTreeJSON.import_data(input, key=None, node=None, **kargs)[source]

Reads a JSON file. This is a simple basic method for the application on the lower layers of the software stack. It is designed for minimal dependencies. The used library is the standard json package. The data is not validated.

Parameters
  • input

    The source of the JSON string data:

    input := (
           <fpname>        # file path name
        |  <file-id>       # file pointer id
        |  <io-stream>     # io stream id
    )
    
    fpname := <json-file-path-name>
    json-file-path-name := (
          <file-path-name>           # with extension
        | <file-path-name> '.json'   # without extension, for multiple syntaxes
    )
    file-id := "open file: file_id = open(<fpname>)"
    io-stream := "open io stream - io_stream = io.StreamIO(<json-string>)"
    json-string := "a valid string in accordance to RFC-7159"
    

  • key

    The key for the insertion point:

    node[key] = <file-data>
    
    default := None - replace self.data,
    

    The caller is responsible for the containment of the provided node within the data structure represented by this object. No checks are performed.

  • node

    The node for the insertion of the read data.:

    default := <top>
    

Returns

Reference to read data structure.

Raises
  • YapyDataConfigError

  • pass-through

5.5.4. Exceptions

exception yapydata.datatree.synjson.YapyDataJSONError[source]

Basic JSON syntax error.