JSON serialization¶
Lossless round-trip of TSeries / MVTSeries / Workspace / MIT / MITRange /
Frequency to and from JSON. Each composite type carries a _type discriminator
so the decoder can rebuild the right class.
tsecon.io.json ¶
JSON round-trip for MIT, Duration, MITRange, TSeries, and Workspace.
The Julia serialize.jl is a binary protocol coupled to Serialization.jl;
it has no JSON. We invent the schema here: every tsecon object is encoded as a
JSON object with a _type discriminator, so a decoder can reconstruct the
right Python type without ambiguity.
Schema (stable starting from this version — a versioned _schema field will
be added if the schema ever needs to change):
MIT→{"_type": "MIT", "freq": <Freq>, "value": <int>}Duration→{"_type": "Duration", "freq": <Freq>, "value": <int>}MITRange→{"_type": "MITRange", "start": <MIT>, "stop": <MIT>, "step": <int>}TSeries→{"_type": "TSeries", "firstdate": <MIT>, "dtype": <str>, "values": [<scalar>...]}MVTSeries→{"_type": "MVTSeries", "firstdate": <MIT>, "dtype": <str>, "names": [<str>, ...], "values": [[<scalar>, ...], ...]}(row-major)Workspace→{"_type": "Workspace", "items": [[<key>, <value>], ...]}
Frequencies are encoded as {"name": <class>, ...}, with the extra parameter
where applicable (end_month for Yearly/HalfYearly/Quarterly, end_day
for Weekly).
NaN / +Inf / -Inf are emitted as JavaScript-style literals (NaN /
Infinity / -Infinity), which is the Python json module's default
when allow_nan=True. Strictly-valid-JSON consumers can pass
allow_nan=False and supply their own sentinel handling.
to_jsonable ¶
Convert a tsecon object (or nested structure) to a plain JSON-friendly tree.
Pure Python int, float, bool, str, None, list, and
dict values pass through unchanged. NumPy scalars are unwrapped via
.item(). NumPy arrays become Python lists.
Source code in src/tsecon/io/json.py
from_jsonable ¶
Inverse of :func:to_jsonable: rebuild tsecon objects from a JSON tree.
Source code in src/tsecon/io/json.py
dumps ¶
Serialize a tsecon (or plain) value to a JSON string.
loads ¶
dump ¶
Write a tsecon (or plain) value as JSON to a writable text stream.