hydra.json.encode module

JSON encoding for Hydra terms. Converts Terms to JSON Values using Either for error handling.

hydra.json.encode.encode_float(fv: FloatValue) object

Encode a float value to JSON. Finite values become JSON numbers (shortest round-trip); IEEE specials (NaN/Inf/-0.0) become JSON strings. Float32 and Float64 are symmetric; the schema disambiguates precision on decode.

hydra.json.encode.encode_integer(iv: IntegerValue) object

Encode an integer value to JSON. Small ints use native numbers; large ints use strings.

hydra.json.encode.encode_literal(lit: Literal) object

Encode a Hydra literal to a JSON value.

hydra.json.encode.requires_json_string_sentinel(s: str) bool

True for IEEE sentinel strings that JSON must escape as a string to preserve.

hydra.json.encode.to_json(types: Mapping[Name, Type], compact_maps: bool, tname: Name, typ: Type, term: Term) object

Encode a Hydra term to a JSON value given a type and type name. Returns Left for unsupported constructs. The compactMaps flag enables the #624 compact object form for string-resolving map keys; it must be False for any caller that reads/writes the checked-in dist/json module-bootstrapping representation (moduleToJson, decodeModuleFromJson, verify-json-kernel), since that wire format is consumed by the published (pre-#624) host and must stay byte-stable. New callers encoding/decoding arbitrary values against a schema (e.g. hydra.build.format digests) may pass True.

hydra.json.encode.to_json_untyped(term: Term) object

Encode a Hydra term to a JSON value without type information. Falls back to array-wrapped Maybe encoding.