mediajson

This module contains methods and classes to extend json encoding and decoding to cover timestamps, uuids, and fractions. The mutable types are provided by default and if you require the immutable types then import from immutable instead.

To make use of it either use the dumps, loads, dump, and load functions in place of the versions from the standard json module, or use the classes NMOSJSONEncoder and NMOSJSONDecoder as your encoder and decoder classes.

 1# Copyright 2017 British Broadcasting Corporation
 2#
 3# Licensed under the Apache License, Version 2.0 (the "License");
 4# you may not use this file except in compliance with the License.
 5# You may obtain a copy of the License at
 6#
 7#     http://www.apache.org/licenses/LICENSE-2.0
 8#
 9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15"""
16This module contains methods and classes to extend json encoding and decoding
17to cover timestamps, uuids, and fractions. The mutable types are provided by
18default and if you require the immutable types then import from immutable instead.
19
20To make use of it either use the dumps, loads, dump, and load functions in
21place of the versions from the standard json module, or use the classes
22NMOSJSONEncoder and NMOSJSONDecoder as your encoder and decoder classes.
23"""
24
25from json import JSONEncoder, JSONDecoder
26
27from .encode import dump, dumps, encode_value, NMOSJSONEncoder
28from .decode import load, loads, decode_value, NMOSJSONDecoder
29
30
31__all__ = ["dump", "dumps", "load", "loads",
32           "encode_value", "decode_value",
33           "JSONEncoder", "JSONDecoder",
34           "NMOSJSONEncoder", "NMOSJSONDecoder"]
def dump( obj: Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]]]]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]]]]]]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]]]]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]]]]]]]]], fp, *args, **kwargs) -> None:
44def dump(obj: MediaJSONSerialisable, fp, *args, **kwargs) -> None:
45    _args = list(args)
46    if 'cls' not in kwargs and len(args) < 7:
47        kwargs['cls'] = NMOSJSONEncoder
48    elif len(_args) >= 5 and _args[4] is None:
49        _args = _args[0:4] + [NMOSJSONEncoder] + _args[5:]
50    return json.dump(obj, fp, *_args, **kwargs)
def dumps( obj: Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]]]]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]]]]]]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]]]]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]]]]]]]]], *args, **kwargs) -> str:
53def dumps(obj: MediaJSONSerialisable, *args, **kwargs) -> str:
54    _args = list(args)
55    if 'cls' not in kwargs and len(args) < 5:
56        kwargs['cls'] = NMOSJSONEncoder
57    elif len(args) >= 5 and args[4] is None:
58        _args = _args[0:4] + [NMOSJSONEncoder] + _args[5:]
59    return json.dumps(obj, *_args, **kwargs)
def load( *args, **kwargs) -> Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]]]]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]]]]]]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]]]]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]]]]]]]]]:
46def load(*args, **kwargs) -> MediaJSONSerialisable:
47    _args = list(args)
48    if 'cls' not in kwargs and len(args) < 3:
49        kwargs['cls'] = NMOSJSONDecoder
50    elif len(args) >= 3 and args[2] is None:
51        _args = _args[0:2] + [NMOSJSONDecoder] + _args[3:]
52    return json.load(*_args, **kwargs)
def loads( *args, **kwargs) -> Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]]]]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]]]]]]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]]]]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]]]]]]]]]:
55def loads(*args, **kwargs) -> MediaJSONSerialisable:
56    _args = list(args)
57    if 'cls' not in kwargs and len(args) < 3:
58        kwargs['cls'] = NMOSJSONDecoder
59    elif len(args) >= 3 and args[2] is None:
60        _args = _args[0:2] + [NMOSJSONDecoder] + _args[3:]
61    return json.loads(*_args, **kwargs)
def encode_value( o: Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]]]]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]]]]]]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]]]]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]]]]]]]]], return_no_encode=True) -> Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]]]]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]]]]]]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]]]]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]]]]]]]], Sequence[Union[str, int, float, Sequence[Union[str, int, float, Sequence[Union[str, int, float, Sequence[Union[str, int, float, Sequence[Any], Mapping[str, Any]]], Mapping[str, Union[str, int, float, Sequence[Any], Mapping[str, Any]]]]], Mapping[str, Union[str, int, float, Sequence[Union[str, int, float, Sequence[Any], Mapping[str, Any]]], Mapping[str, Union[str, int, float, Sequence[Any], Mapping[str, Any]]]]]]], Mapping[str, Union[str, int, float, Sequence[Union[str, int, float, Sequence[Union[str, int, float, Sequence[Any], Mapping[str, Any]]], Mapping[str, Union[str, int, float, Sequence[Any], Mapping[str, Any]]]]], Mapping[str, Union[str, int, float, Sequence[Union[str, int, float, Sequence[Any], Mapping[str, Any]]], Mapping[str, Union[str, int, float, Sequence[Any], Mapping[str, Any]]]]]]]]], Mapping[str, Union[str, int, float, Sequence[Union[str, int, float, Sequence[Union[str, int, float, Sequence[Union[str, int, float, Sequence[Any], Mapping[str, Any]]], Mapping[str, Union[str, int, float, Sequence[Any], Mapping[str, Any]]]]], Mapping[str, Union[str, int, float, Sequence[Union[str, int, float, Sequence[Any], Mapping[str, Any]]], Mapping[str, Union[str, int, float, Sequence[Any], Mapping[str, Any]]]]]]], Mapping[str, Union[str, int, float, Sequence[Union[str, int, float, Sequence[Union[str, int, float, Sequence[Any], Mapping[str, Any]]], Mapping[str, Union[str, int, float, Sequence[Any], Mapping[str, Any]]]]], Mapping[str, Union[str, int, float, Sequence[Union[str, int, float, Sequence[Any], Mapping[str, Any]]], Mapping[str, Union[str, int, float, Sequence[Any], Mapping[str, Any]]]]]]]]], NoneType]:
62def encode_value(o: MediaJSONSerialisable,
63                 return_no_encode=True) -> Union[MediaJSONSerialisable, Optional[JSONSerialisable]]:
64    if isinstance(o, dict):
65        if not return_no_encode:
66            return None
67        res = {}
68        for key in o:
69            res[key] = encode_value(o[key])
70        return cast(MediaJSONSerialisable, res)
71    elif isinstance(o, list):
72        if not return_no_encode:
73            return None
74        return cast(MediaJSONSerialisable, [encode_value(v) for v in o])
75    elif isinstance(o, uuid.UUID):
76        return str(o)
77    elif isinstance(o, Timestamp):
78        return o.to_sec_nsec()
79    elif isinstance(o, TimeRange):
80        return o.to_sec_nsec_range()
81    elif isinstance(o, Fraction):
82        return {"numerator": o.numerator,
83                "denominator": o.denominator}
84    elif isinstance(o, SupportsMediaTimestamp):
85        return mediatimestamp(o).to_tai_sec_nsec()
86    elif isinstance(o, SupportsMediaTimeRange):
87        return mediatimerange(o).to_sec_nsec_range()
88    else:
89        return o if return_no_encode else None
def decode_value( o: Union[str, int, float, Sequence[Union[str, int, float, Sequence[Union[str, int, float, Sequence[Union[str, int, float, Sequence[Union[str, int, float, Sequence[Any], Mapping[str, Any]]], Mapping[str, Union[str, int, float, Sequence[Any], Mapping[str, Any]]]]], Mapping[str, Union[str, int, float, Sequence[Union[str, int, float, Sequence[Any], Mapping[str, Any]]], Mapping[str, Union[str, int, float, Sequence[Any], Mapping[str, Any]]]]]]], Mapping[str, Union[str, int, float, Sequence[Union[str, int, float, Sequence[Union[str, int, float, Sequence[Any], Mapping[str, Any]]], Mapping[str, Union[str, int, float, Sequence[Any], Mapping[str, Any]]]]], Mapping[str, Union[str, int, float, Sequence[Union[str, int, float, Sequence[Any], Mapping[str, Any]]], Mapping[str, Union[str, int, float, Sequence[Any], Mapping[str, Any]]]]]]]]], Mapping[str, Union[str, int, float, Sequence[Union[str, int, float, Sequence[Union[str, int, float, Sequence[Union[str, int, float, Sequence[Any], Mapping[str, Any]]], Mapping[str, Union[str, int, float, Sequence[Any], Mapping[str, Any]]]]], Mapping[str, Union[str, int, float, Sequence[Union[str, int, float, Sequence[Any], Mapping[str, Any]]], Mapping[str, Union[str, int, float, Sequence[Any], Mapping[str, Any]]]]]]], Mapping[str, Union[str, int, float, Sequence[Union[str, int, float, Sequence[Union[str, int, float, Sequence[Any], Mapping[str, Any]]], Mapping[str, Union[str, int, float, Sequence[Any], Mapping[str, Any]]]]], Mapping[str, Union[str, int, float, Sequence[Union[str, int, float, Sequence[Any], Mapping[str, Any]]], Mapping[str, Union[str, int, float, Sequence[Any], Mapping[str, Any]]]]]]]]]]) -> Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]]]]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]]]]]]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]]]]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]]]]]]]]]:
64def decode_value(o: JSONSerialisable) -> MediaJSONSerialisable:
65    if isinstance(o, dict):
66        if len(o.keys()) == 2 and "numerator" in o and "denominator" in o:
67            return Fraction(o['numerator'], o['denominator'])
68        else:
69            res = {}
70            for key in o:
71                res[key] = decode_value(o[key])
72            return res
73    elif isinstance(o, list):
74        return [decode_value(v) for v in o]
75    elif isinstance(o, str):
76        if re.match(UUID_REGEX,
77                    o):
78            return uuid.UUID(o)
79        elif re.match(r'^-?\d+:\d+$', o):
80            return Timestamp.from_sec_nsec(o)
81        elif re.match(r'^(\(|\[)?(-?\d+:\d+)?_(-?\d+:\d+)?(\)|\])?$', o):
82            return TimeRange.from_str(o)
83        elif o == "()":
84            return TimeRange.never()
85    return o
class JSONEncoder:
 75class JSONEncoder(object):
 76    """Extensible JSON <https://json.org> encoder for Python data structures.
 77
 78    Supports the following objects and types by default:
 79
 80    +-------------------+---------------+
 81    | Python            | JSON          |
 82    +===================+===============+
 83    | dict              | object        |
 84    +-------------------+---------------+
 85    | list, tuple       | array         |
 86    +-------------------+---------------+
 87    | str               | string        |
 88    +-------------------+---------------+
 89    | int, float        | number        |
 90    +-------------------+---------------+
 91    | True              | true          |
 92    +-------------------+---------------+
 93    | False             | false         |
 94    +-------------------+---------------+
 95    | None              | null          |
 96    +-------------------+---------------+
 97
 98    To extend this to recognize other objects, subclass and implement a
 99    ``.default()`` method with another method that returns a serializable
100    object for ``o`` if possible, otherwise it should call the superclass
101    implementation (to raise ``TypeError``).
102
103    """
104    item_separator = ', '
105    key_separator = ': '
106    def __init__(self, *, skipkeys=False, ensure_ascii=True,
107            check_circular=True, allow_nan=True, sort_keys=False,
108            indent=None, separators=None, default=None):
109        """Constructor for JSONEncoder, with sensible defaults.
110
111        If skipkeys is false, then it is a TypeError to attempt
112        encoding of keys that are not str, int, float or None.  If
113        skipkeys is True, such items are simply skipped.
114
115        If ensure_ascii is true, the output is guaranteed to be str
116        objects with all incoming non-ASCII characters escaped.  If
117        ensure_ascii is false, the output can contain non-ASCII characters.
118
119        If check_circular is true, then lists, dicts, and custom encoded
120        objects will be checked for circular references during encoding to
121        prevent an infinite recursion (which would cause an RecursionError).
122        Otherwise, no such check takes place.
123
124        If allow_nan is true, then NaN, Infinity, and -Infinity will be
125        encoded as such.  This behavior is not JSON specification compliant,
126        but is consistent with most JavaScript based encoders and decoders.
127        Otherwise, it will be a ValueError to encode such floats.
128
129        If sort_keys is true, then the output of dictionaries will be
130        sorted by key; this is useful for regression tests to ensure
131        that JSON serializations can be compared on a day-to-day basis.
132
133        If indent is a non-negative integer, then JSON array
134        elements and object members will be pretty-printed with that
135        indent level.  An indent level of 0 will only insert newlines.
136        None is the most compact representation.
137
138        If specified, separators should be an (item_separator, key_separator)
139        tuple.  The default is (', ', ': ') if *indent* is ``None`` and
140        (',', ': ') otherwise.  To get the most compact JSON representation,
141        you should specify (',', ':') to eliminate whitespace.
142
143        If specified, default is a function that gets called for objects
144        that can't otherwise be serialized.  It should return a JSON encodable
145        version of the object or raise a ``TypeError``.
146
147        """
148
149        self.skipkeys = skipkeys
150        self.ensure_ascii = ensure_ascii
151        self.check_circular = check_circular
152        self.allow_nan = allow_nan
153        self.sort_keys = sort_keys
154        self.indent = indent
155        if separators is not None:
156            self.item_separator, self.key_separator = separators
157        elif indent is not None:
158            self.item_separator = ','
159        if default is not None:
160            self.default = default
161
162    def default(self, o):
163        """Implement this method in a subclass such that it returns
164        a serializable object for ``o``, or calls the base implementation
165        (to raise a ``TypeError``).
166
167        For example, to support arbitrary iterators, you could
168        implement default like this::
169
170            def default(self, o):
171                try:
172                    iterable = iter(o)
173                except TypeError:
174                    pass
175                else:
176                    return list(iterable)
177                # Let the base class default method raise the TypeError
178                return JSONEncoder.default(self, o)
179
180        """
181        raise TypeError(f'Object of type {o.__class__.__name__} '
182                        f'is not JSON serializable')
183
184    def encode(self, o):
185        """Return a JSON string representation of a Python data structure.
186
187        >>> from json.encoder import JSONEncoder
188        >>> JSONEncoder().encode({"foo": ["bar", "baz"]})
189        '{"foo": ["bar", "baz"]}'
190
191        """
192        # This is for extremely simple cases and benchmarks.
193        if isinstance(o, str):
194            if self.ensure_ascii:
195                return encode_basestring_ascii(o)
196            else:
197                return encode_basestring(o)
198        # This doesn't pass the iterator directly to ''.join() because the
199        # exceptions aren't as detailed.  The list call should be roughly
200        # equivalent to the PySequence_Fast that ''.join() would do.
201        chunks = self.iterencode(o, _one_shot=True)
202        if not isinstance(chunks, (list, tuple)):
203            chunks = list(chunks)
204        return ''.join(chunks)
205
206    def iterencode(self, o, _one_shot=False):
207        """Encode the given object and yield each string
208        representation as available.
209
210        For example::
211
212            for chunk in JSONEncoder().iterencode(bigobject):
213                mysocket.write(chunk)
214
215        """
216        if self.check_circular:
217            markers = {}
218        else:
219            markers = None
220        if self.ensure_ascii:
221            _encoder = encode_basestring_ascii
222        else:
223            _encoder = encode_basestring
224
225        def floatstr(o, allow_nan=self.allow_nan,
226                _repr=float.__repr__, _inf=INFINITY, _neginf=-INFINITY):
227            # Check for specials.  Note that this type of test is processor
228            # and/or platform-specific, so do tests which don't depend on the
229            # internals.
230
231            if o != o:
232                text = 'NaN'
233            elif o == _inf:
234                text = 'Infinity'
235            elif o == _neginf:
236                text = '-Infinity'
237            else:
238                return _repr(o)
239
240            if not allow_nan:
241                raise ValueError(
242                    "Out of range float values are not JSON compliant: " +
243                    repr(o))
244
245            return text
246
247
248        if (_one_shot and c_make_encoder is not None
249                and self.indent is None):
250            _iterencode = c_make_encoder(
251                markers, self.default, _encoder, self.indent,
252                self.key_separator, self.item_separator, self.sort_keys,
253                self.skipkeys, self.allow_nan)
254        else:
255            _iterencode = _make_iterencode(
256                markers, self.default, _encoder, self.indent, floatstr,
257                self.key_separator, self.item_separator, self.sort_keys,
258                self.skipkeys, _one_shot)
259        return _iterencode(o, 0)

Extensible JSON https://json.org encoder for Python data structures.

Supports the following objects and types by default:

+-------------------+---------------+ | Python | JSON | +===================+===============+ | dict | object | +-------------------+---------------+ | list, tuple | array | +-------------------+---------------+ | str | string | +-------------------+---------------+ | int, float | number | +-------------------+---------------+ | True | true | +-------------------+---------------+ | False | false | +-------------------+---------------+ | None | null | +-------------------+---------------+

To extend this to recognize other objects, subclass and implement a .default() method with another method that returns a serializable object for o if possible, otherwise it should call the superclass implementation (to raise TypeError).

JSONEncoder( *, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)
106    def __init__(self, *, skipkeys=False, ensure_ascii=True,
107            check_circular=True, allow_nan=True, sort_keys=False,
108            indent=None, separators=None, default=None):
109        """Constructor for JSONEncoder, with sensible defaults.
110
111        If skipkeys is false, then it is a TypeError to attempt
112        encoding of keys that are not str, int, float or None.  If
113        skipkeys is True, such items are simply skipped.
114
115        If ensure_ascii is true, the output is guaranteed to be str
116        objects with all incoming non-ASCII characters escaped.  If
117        ensure_ascii is false, the output can contain non-ASCII characters.
118
119        If check_circular is true, then lists, dicts, and custom encoded
120        objects will be checked for circular references during encoding to
121        prevent an infinite recursion (which would cause an RecursionError).
122        Otherwise, no such check takes place.
123
124        If allow_nan is true, then NaN, Infinity, and -Infinity will be
125        encoded as such.  This behavior is not JSON specification compliant,
126        but is consistent with most JavaScript based encoders and decoders.
127        Otherwise, it will be a ValueError to encode such floats.
128
129        If sort_keys is true, then the output of dictionaries will be
130        sorted by key; this is useful for regression tests to ensure
131        that JSON serializations can be compared on a day-to-day basis.
132
133        If indent is a non-negative integer, then JSON array
134        elements and object members will be pretty-printed with that
135        indent level.  An indent level of 0 will only insert newlines.
136        None is the most compact representation.
137
138        If specified, separators should be an (item_separator, key_separator)
139        tuple.  The default is (', ', ': ') if *indent* is ``None`` and
140        (',', ': ') otherwise.  To get the most compact JSON representation,
141        you should specify (',', ':') to eliminate whitespace.
142
143        If specified, default is a function that gets called for objects
144        that can't otherwise be serialized.  It should return a JSON encodable
145        version of the object or raise a ``TypeError``.
146
147        """
148
149        self.skipkeys = skipkeys
150        self.ensure_ascii = ensure_ascii
151        self.check_circular = check_circular
152        self.allow_nan = allow_nan
153        self.sort_keys = sort_keys
154        self.indent = indent
155        if separators is not None:
156            self.item_separator, self.key_separator = separators
157        elif indent is not None:
158            self.item_separator = ','
159        if default is not None:
160            self.default = default

Constructor for JSONEncoder, with sensible defaults.

If skipkeys is false, then it is a TypeError to attempt encoding of keys that are not str, int, float or None. If skipkeys is True, such items are simply skipped.

If ensure_ascii is true, the output is guaranteed to be str objects with all incoming non-ASCII characters escaped. If ensure_ascii is false, the output can contain non-ASCII characters.

If check_circular is true, then lists, dicts, and custom encoded objects will be checked for circular references during encoding to prevent an infinite recursion (which would cause an RecursionError). Otherwise, no such check takes place.

If allow_nan is true, then NaN, Infinity, and -Infinity will be encoded as such. This behavior is not JSON specification compliant, but is consistent with most JavaScript based encoders and decoders. Otherwise, it will be a ValueError to encode such floats.

If sort_keys is true, then the output of dictionaries will be sorted by key; this is useful for regression tests to ensure that JSON serializations can be compared on a day-to-day basis.

If indent is a non-negative integer, then JSON array elements and object members will be pretty-printed with that indent level. An indent level of 0 will only insert newlines. None is the most compact representation.

If specified, separators should be an (item_separator, key_separator) tuple. The default is (', ', ': ') if indent is None and (',', ': ') otherwise. To get the most compact JSON representation, you should specify (',', ':') to eliminate whitespace.

If specified, default is a function that gets called for objects that can't otherwise be serialized. It should return a JSON encodable version of the object or raise a TypeError.

item_separator = ', '
key_separator = ': '
skipkeys
ensure_ascii
check_circular
allow_nan
sort_keys
indent
def default(self, o):
162    def default(self, o):
163        """Implement this method in a subclass such that it returns
164        a serializable object for ``o``, or calls the base implementation
165        (to raise a ``TypeError``).
166
167        For example, to support arbitrary iterators, you could
168        implement default like this::
169
170            def default(self, o):
171                try:
172                    iterable = iter(o)
173                except TypeError:
174                    pass
175                else:
176                    return list(iterable)
177                # Let the base class default method raise the TypeError
178                return JSONEncoder.default(self, o)
179
180        """
181        raise TypeError(f'Object of type {o.__class__.__name__} '
182                        f'is not JSON serializable')

Implement this method in a subclass such that it returns a serializable object for o, or calls the base implementation (to raise a TypeError).

For example, to support arbitrary iterators, you could implement default like this::

def default(self, o):
    try:
        iterable = iter(o)
    except TypeError:
        pass
    else:
        return list(iterable)
    # Let the base class default method raise the TypeError
    return JSONEncoder.default(self, o)
def encode(self, o):
184    def encode(self, o):
185        """Return a JSON string representation of a Python data structure.
186
187        >>> from json.encoder import JSONEncoder
188        >>> JSONEncoder().encode({"foo": ["bar", "baz"]})
189        '{"foo": ["bar", "baz"]}'
190
191        """
192        # This is for extremely simple cases and benchmarks.
193        if isinstance(o, str):
194            if self.ensure_ascii:
195                return encode_basestring_ascii(o)
196            else:
197                return encode_basestring(o)
198        # This doesn't pass the iterator directly to ''.join() because the
199        # exceptions aren't as detailed.  The list call should be roughly
200        # equivalent to the PySequence_Fast that ''.join() would do.
201        chunks = self.iterencode(o, _one_shot=True)
202        if not isinstance(chunks, (list, tuple)):
203            chunks = list(chunks)
204        return ''.join(chunks)

Return a JSON string representation of a Python data structure.

>>> from json.encoder import JSONEncoder
>>> JSONEncoder().encode({"foo": ["bar", "baz"]})
'{"foo": ["bar", "baz"]}'
def iterencode(self, o, _one_shot=False):
206    def iterencode(self, o, _one_shot=False):
207        """Encode the given object and yield each string
208        representation as available.
209
210        For example::
211
212            for chunk in JSONEncoder().iterencode(bigobject):
213                mysocket.write(chunk)
214
215        """
216        if self.check_circular:
217            markers = {}
218        else:
219            markers = None
220        if self.ensure_ascii:
221            _encoder = encode_basestring_ascii
222        else:
223            _encoder = encode_basestring
224
225        def floatstr(o, allow_nan=self.allow_nan,
226                _repr=float.__repr__, _inf=INFINITY, _neginf=-INFINITY):
227            # Check for specials.  Note that this type of test is processor
228            # and/or platform-specific, so do tests which don't depend on the
229            # internals.
230
231            if o != o:
232                text = 'NaN'
233            elif o == _inf:
234                text = 'Infinity'
235            elif o == _neginf:
236                text = '-Infinity'
237            else:
238                return _repr(o)
239
240            if not allow_nan:
241                raise ValueError(
242                    "Out of range float values are not JSON compliant: " +
243                    repr(o))
244
245            return text
246
247
248        if (_one_shot and c_make_encoder is not None
249                and self.indent is None):
250            _iterencode = c_make_encoder(
251                markers, self.default, _encoder, self.indent,
252                self.key_separator, self.item_separator, self.sort_keys,
253                self.skipkeys, self.allow_nan)
254        else:
255            _iterencode = _make_iterencode(
256                markers, self.default, _encoder, self.indent, floatstr,
257                self.key_separator, self.item_separator, self.sort_keys,
258                self.skipkeys, _one_shot)
259        return _iterencode(o, 0)

Encode the given object and yield each string representation as available.

For example::

for chunk in JSONEncoder().iterencode(bigobject):
    mysocket.write(chunk)
class JSONDecoder:
255class JSONDecoder(object):
256    """Simple JSON <https://json.org> decoder
257
258    Performs the following translations in decoding by default:
259
260    +---------------+-------------------+
261    | JSON          | Python            |
262    +===============+===================+
263    | object        | dict              |
264    +---------------+-------------------+
265    | array         | list              |
266    +---------------+-------------------+
267    | string        | str               |
268    +---------------+-------------------+
269    | number (int)  | int               |
270    +---------------+-------------------+
271    | number (real) | float             |
272    +---------------+-------------------+
273    | true          | True              |
274    +---------------+-------------------+
275    | false         | False             |
276    +---------------+-------------------+
277    | null          | None              |
278    +---------------+-------------------+
279
280    It also understands ``NaN``, ``Infinity``, and ``-Infinity`` as
281    their corresponding ``float`` values, which is outside the JSON spec.
282
283    """
284
285    def __init__(self, *, object_hook=None, parse_float=None,
286            parse_int=None, parse_constant=None, strict=True,
287            object_pairs_hook=None):
288        """``object_hook``, if specified, will be called with the result
289        of every JSON object decoded and its return value will be used in
290        place of the given ``dict``.  This can be used to provide custom
291        deserializations (e.g. to support JSON-RPC class hinting).
292
293        ``object_pairs_hook``, if specified will be called with the result of
294        every JSON object decoded with an ordered list of pairs.  The return
295        value of ``object_pairs_hook`` will be used instead of the ``dict``.
296        This feature can be used to implement custom decoders.
297        If ``object_hook`` is also defined, the ``object_pairs_hook`` takes
298        priority.
299
300        ``parse_float``, if specified, will be called with the string
301        of every JSON float to be decoded. By default this is equivalent to
302        float(num_str). This can be used to use another datatype or parser
303        for JSON floats (e.g. decimal.Decimal).
304
305        ``parse_int``, if specified, will be called with the string
306        of every JSON int to be decoded. By default this is equivalent to
307        int(num_str). This can be used to use another datatype or parser
308        for JSON integers (e.g. float).
309
310        ``parse_constant``, if specified, will be called with one of the
311        following strings: -Infinity, Infinity, NaN.
312        This can be used to raise an exception if invalid JSON numbers
313        are encountered.
314
315        If ``strict`` is false (true is the default), then control
316        characters will be allowed inside strings.  Control characters in
317        this context are those with character codes in the 0-31 range,
318        including ``'\\t'`` (tab), ``'\\n'``, ``'\\r'`` and ``'\\0'``.
319        """
320        self.object_hook = object_hook
321        self.parse_float = parse_float or float
322        self.parse_int = parse_int or int
323        self.parse_constant = parse_constant or _CONSTANTS.__getitem__
324        self.strict = strict
325        self.object_pairs_hook = object_pairs_hook
326        self.parse_object = JSONObject
327        self.parse_array = JSONArray
328        self.parse_string = scanstring
329        self.memo = {}
330        self.scan_once = scanner.make_scanner(self)
331
332
333    def decode(self, s, _w=WHITESPACE.match):
334        """Return the Python representation of ``s`` (a ``str`` instance
335        containing a JSON document).
336
337        """
338        obj, end = self.raw_decode(s, idx=_w(s, 0).end())
339        end = _w(s, end).end()
340        if end != len(s):
341            raise JSONDecodeError("Extra data", s, end)
342        return obj
343
344    def raw_decode(self, s, idx=0):
345        """Decode a JSON document from ``s`` (a ``str`` beginning with
346        a JSON document) and return a 2-tuple of the Python
347        representation and the index in ``s`` where the document ended.
348
349        This can be used to decode a JSON document from a string that may
350        have extraneous data at the end.
351
352        """
353        try:
354            obj, end = self.scan_once(s, idx)
355        except StopIteration as err:
356            raise JSONDecodeError("Expecting value", s, err.value) from None
357        return obj, end

Simple JSON https://json.org decoder

Performs the following translations in decoding by default:

+---------------+-------------------+ | JSON | Python | +===============+===================+ | object | dict | +---------------+-------------------+ | array | list | +---------------+-------------------+ | string | str | +---------------+-------------------+ | number (int) | int | +---------------+-------------------+ | number (real) | float | +---------------+-------------------+ | true | True | +---------------+-------------------+ | false | False | +---------------+-------------------+ | null | None | +---------------+-------------------+

It also understands NaN, Infinity, and -Infinity as their corresponding float values, which is outside the JSON spec.

JSONDecoder( *, object_hook=None, parse_float=None, parse_int=None, parse_constant=None, strict=True, object_pairs_hook=None)
285    def __init__(self, *, object_hook=None, parse_float=None,
286            parse_int=None, parse_constant=None, strict=True,
287            object_pairs_hook=None):
288        """``object_hook``, if specified, will be called with the result
289        of every JSON object decoded and its return value will be used in
290        place of the given ``dict``.  This can be used to provide custom
291        deserializations (e.g. to support JSON-RPC class hinting).
292
293        ``object_pairs_hook``, if specified will be called with the result of
294        every JSON object decoded with an ordered list of pairs.  The return
295        value of ``object_pairs_hook`` will be used instead of the ``dict``.
296        This feature can be used to implement custom decoders.
297        If ``object_hook`` is also defined, the ``object_pairs_hook`` takes
298        priority.
299
300        ``parse_float``, if specified, will be called with the string
301        of every JSON float to be decoded. By default this is equivalent to
302        float(num_str). This can be used to use another datatype or parser
303        for JSON floats (e.g. decimal.Decimal).
304
305        ``parse_int``, if specified, will be called with the string
306        of every JSON int to be decoded. By default this is equivalent to
307        int(num_str). This can be used to use another datatype or parser
308        for JSON integers (e.g. float).
309
310        ``parse_constant``, if specified, will be called with one of the
311        following strings: -Infinity, Infinity, NaN.
312        This can be used to raise an exception if invalid JSON numbers
313        are encountered.
314
315        If ``strict`` is false (true is the default), then control
316        characters will be allowed inside strings.  Control characters in
317        this context are those with character codes in the 0-31 range,
318        including ``'\\t'`` (tab), ``'\\n'``, ``'\\r'`` and ``'\\0'``.
319        """
320        self.object_hook = object_hook
321        self.parse_float = parse_float or float
322        self.parse_int = parse_int or int
323        self.parse_constant = parse_constant or _CONSTANTS.__getitem__
324        self.strict = strict
325        self.object_pairs_hook = object_pairs_hook
326        self.parse_object = JSONObject
327        self.parse_array = JSONArray
328        self.parse_string = scanstring
329        self.memo = {}
330        self.scan_once = scanner.make_scanner(self)

object_hook, if specified, will be called with the result of every JSON object decoded and its return value will be used in place of the given dict. This can be used to provide custom deserializations (e.g. to support JSON-RPC class hinting).

object_pairs_hook, if specified will be called with the result of every JSON object decoded with an ordered list of pairs. The return value of object_pairs_hook will be used instead of the dict. This feature can be used to implement custom decoders. If object_hook is also defined, the object_pairs_hook takes priority.

parse_float, if specified, will be called with the string of every JSON float to be decoded. By default this is equivalent to float(num_str). This can be used to use another datatype or parser for JSON floats (e.g. decimal.Decimal).

parse_int, if specified, will be called with the string of every JSON int to be decoded. By default this is equivalent to int(num_str). This can be used to use another datatype or parser for JSON integers (e.g. float).

parse_constant, if specified, will be called with one of the following strings: -Infinity, Infinity, NaN. This can be used to raise an exception if invalid JSON numbers are encountered.

If strict is false (true is the default), then control characters will be allowed inside strings. Control characters in this context are those with character codes in the 0-31 range, including '\t' (tab), '\n', '\r' and '\0'.

object_hook
parse_float
parse_int
parse_constant
strict
object_pairs_hook
parse_object
parse_array
parse_string
memo
scan_once
def decode(self, s, _w=<built-in method match of re.Pattern object>):
333    def decode(self, s, _w=WHITESPACE.match):
334        """Return the Python representation of ``s`` (a ``str`` instance
335        containing a JSON document).
336
337        """
338        obj, end = self.raw_decode(s, idx=_w(s, 0).end())
339        end = _w(s, end).end()
340        if end != len(s):
341            raise JSONDecodeError("Extra data", s, end)
342        return obj

Return the Python representation of s (a str instance containing a JSON document).

def raw_decode(self, s, idx=0):
344    def raw_decode(self, s, idx=0):
345        """Decode a JSON document from ``s`` (a ``str`` beginning with
346        a JSON document) and return a 2-tuple of the Python
347        representation and the index in ``s`` where the document ended.
348
349        This can be used to decode a JSON document from a string that may
350        have extraneous data at the end.
351
352        """
353        try:
354            obj, end = self.scan_once(s, idx)
355        except StopIteration as err:
356            raise JSONDecodeError("Expecting value", s, err.value) from None
357        return obj, end

Decode a JSON document from s (a str beginning with a JSON document) and return a 2-tuple of the Python representation and the index in s where the document ended.

This can be used to decode a JSON document from a string that may have extraneous data at the end.

class NMOSJSONEncoder(mediajson.JSONEncoder):
 96class NMOSJSONEncoder(JSONEncoder):
 97    def default(self, o: MediaJSONSerialisable) -> JSONSerialisable:
 98        result = cast(Optional[JSONSerialisable], encode_value_or_fail(o))
 99        if result is not None:
100            return result
101        else:
102            return super(NMOSJSONEncoder, self).default(o)

Extensible JSON https://json.org encoder for Python data structures.

Supports the following objects and types by default:

+-------------------+---------------+ | Python | JSON | +===================+===============+ | dict | object | +-------------------+---------------+ | list, tuple | array | +-------------------+---------------+ | str | string | +-------------------+---------------+ | int, float | number | +-------------------+---------------+ | True | true | +-------------------+---------------+ | False | false | +-------------------+---------------+ | None | null | +-------------------+---------------+

To extend this to recognize other objects, subclass and implement a .default() method with another method that returns a serializable object for o if possible, otherwise it should call the superclass implementation (to raise TypeError).

def default( self, o: Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]]]]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]]]]]]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]]]]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]]]]]]]]]) -> Union[str, int, float, Sequence[Union[str, int, float, Sequence[Union[str, int, float, Sequence[Union[str, int, float, Sequence[Union[str, int, float, Sequence[Any], Mapping[str, Any]]], Mapping[str, Union[str, int, float, Sequence[Any], Mapping[str, Any]]]]], Mapping[str, Union[str, int, float, Sequence[Union[str, int, float, Sequence[Any], Mapping[str, Any]]], Mapping[str, Union[str, int, float, Sequence[Any], Mapping[str, Any]]]]]]], Mapping[str, Union[str, int, float, Sequence[Union[str, int, float, Sequence[Union[str, int, float, Sequence[Any], Mapping[str, Any]]], Mapping[str, Union[str, int, float, Sequence[Any], Mapping[str, Any]]]]], Mapping[str, Union[str, int, float, Sequence[Union[str, int, float, Sequence[Any], Mapping[str, Any]]], Mapping[str, Union[str, int, float, Sequence[Any], Mapping[str, Any]]]]]]]]], Mapping[str, Union[str, int, float, Sequence[Union[str, int, float, Sequence[Union[str, int, float, Sequence[Union[str, int, float, Sequence[Any], Mapping[str, Any]]], Mapping[str, Union[str, int, float, Sequence[Any], Mapping[str, Any]]]]], Mapping[str, Union[str, int, float, Sequence[Union[str, int, float, Sequence[Any], Mapping[str, Any]]], Mapping[str, Union[str, int, float, Sequence[Any], Mapping[str, Any]]]]]]], Mapping[str, Union[str, int, float, Sequence[Union[str, int, float, Sequence[Union[str, int, float, Sequence[Any], Mapping[str, Any]]], Mapping[str, Union[str, int, float, Sequence[Any], Mapping[str, Any]]]]], Mapping[str, Union[str, int, float, Sequence[Union[str, int, float, Sequence[Any], Mapping[str, Any]]], Mapping[str, Union[str, int, float, Sequence[Any], Mapping[str, Any]]]]]]]]]]:
 97    def default(self, o: MediaJSONSerialisable) -> JSONSerialisable:
 98        result = cast(Optional[JSONSerialisable], encode_value_or_fail(o))
 99        if result is not None:
100            return result
101        else:
102            return super(NMOSJSONEncoder, self).default(o)

Implement this method in a subclass such that it returns a serializable object for o, or calls the base implementation (to raise a TypeError).

For example, to support arbitrary iterators, you could implement default like this::

def default(self, o):
    try:
        iterable = iter(o)
    except TypeError:
        pass
    else:
        return list(iterable)
    # Let the base class default method raise the TypeError
    return JSONEncoder.default(self, o)
class NMOSJSONDecoder(mediajson.JSONDecoder):
 88class NMOSJSONDecoder(JSONDecoder):
 89    def __init__(self, **kwargs):
 90        # Filter out the 'encoding' parameter as a simple workaround for simplejson adding it.
 91        # The parameter is no longer supported in python 3.
 92        py3_kwargs = {
 93            key: value
 94            for (key, value) in kwargs.items()
 95            if key != "encoding"
 96        }
 97        super().__init__(**py3_kwargs)
 98
 99    def raw_decode(self, s: str, *args, **kwargs) -> Tuple[MediaJSONSerialisable, int]:
100        value: JSONSerialisable
101        (value, offset) = super(NMOSJSONDecoder, self).raw_decode(s,
102                                                                  *args,
103                                                                  **kwargs)
104        return (decode_value(value), offset)

Simple JSON https://json.org decoder

Performs the following translations in decoding by default:

+---------------+-------------------+ | JSON | Python | +===============+===================+ | object | dict | +---------------+-------------------+ | array | list | +---------------+-------------------+ | string | str | +---------------+-------------------+ | number (int) | int | +---------------+-------------------+ | number (real) | float | +---------------+-------------------+ | true | True | +---------------+-------------------+ | false | False | +---------------+-------------------+ | null | None | +---------------+-------------------+

It also understands NaN, Infinity, and -Infinity as their corresponding float values, which is outside the JSON spec.

NMOSJSONDecoder(**kwargs)
89    def __init__(self, **kwargs):
90        # Filter out the 'encoding' parameter as a simple workaround for simplejson adding it.
91        # The parameter is no longer supported in python 3.
92        py3_kwargs = {
93            key: value
94            for (key, value) in kwargs.items()
95            if key != "encoding"
96        }
97        super().__init__(**py3_kwargs)

object_hook, if specified, will be called with the result of every JSON object decoded and its return value will be used in place of the given dict. This can be used to provide custom deserializations (e.g. to support JSON-RPC class hinting).

object_pairs_hook, if specified will be called with the result of every JSON object decoded with an ordered list of pairs. The return value of object_pairs_hook will be used instead of the dict. This feature can be used to implement custom decoders. If object_hook is also defined, the object_pairs_hook takes priority.

parse_float, if specified, will be called with the string of every JSON float to be decoded. By default this is equivalent to float(num_str). This can be used to use another datatype or parser for JSON floats (e.g. decimal.Decimal).

parse_int, if specified, will be called with the string of every JSON int to be decoded. By default this is equivalent to int(num_str). This can be used to use another datatype or parser for JSON integers (e.g. float).

parse_constant, if specified, will be called with one of the following strings: -Infinity, Infinity, NaN. This can be used to raise an exception if invalid JSON numbers are encountered.

If strict is false (true is the default), then control characters will be allowed inside strings. Control characters in this context are those with character codes in the 0-31 range, including '\t' (tab), '\n', '\r' and '\0'.

def raw_decode( self, s: str, *args, **kwargs) -> Tuple[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]]]]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]]]]]]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]]]]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]], Mapping[str, Union[str, int, float, uuid.UUID, mediatimestamp.immutable.timestamp.SupportsMediaTimestamp, mediatimestamp.immutable.timerange.SupportsMediaTimeRange, fractions.Fraction, Sequence[Any], Mapping[str, Any]]]]]]]]]], int]:
 99    def raw_decode(self, s: str, *args, **kwargs) -> Tuple[MediaJSONSerialisable, int]:
100        value: JSONSerialisable
101        (value, offset) = super(NMOSJSONDecoder, self).raw_decode(s,
102                                                                  *args,
103                                                                  **kwargs)
104        return (decode_value(value), offset)

Decode a JSON document from s (a str beginning with a JSON document) and return a 2-tuple of the Python representation and the index in s where the document ended.

This can be used to decode a JSON document from a string that may have extraneous data at the end.