10.12 JSON: schemas, null and machine use
JSON is preferable when an output contains nested objects, arrays, typed booleans or metadata that would be awkward to flatten into CSV. nlmx serializes its results to JSON, sanitizes the resulting value, writes pretty-printed JSON and appends a final newline.
Non-finite numbers
JSON has no standard literal for NaN or infinity. The serialization path maps non-finite floating-point values to null. A consumer must distinguish this from a real numeric zero and, when scientifically important, from other reasons for missingness. If the reason matters, a robust schema pairs the nullable value with a status or reason field.
Object order and whitespace
Pretty printing improves human inspection, but whitespace is not semantic. Object member order should not be used as an API contract unless the specific schema says otherwise. A regression test that compares parsed values is often more resilient than byte comparison after a harmless formatter change; a release-integrity check should still compare exact archived bytes through SHA-256.
This distinction mirrors Chapter 9's reproducibility levels: semantic identity and byte identity answer different questions.
Schema versioning
Machine consumers should validate required keys, types and acceptable value ranges. For durable automation, include or externally pin the nlmx version and file schema expectation. Additive fields are often compatible with name-based readers; renaming a key, changing units or changing number to formatted string is not.
Example consumer logic should fail clearly when a required key is missing:
parse JSON
assert root is an object
assert engine/version expectation is satisfied
assert required numeric keys are number or documented null
validate arrays, units and identifier uniqueness
only then calculate
JSON is not a report
Indentation makes JSON readable, but it lacks the explanatory hierarchy, captions and warnings of the HTML/text reports. Likewise, copying a JSON block into a submission does not explain method or provenance. Use it as the structured truth for software, then connect it to human-readable interpretation.
Security and scale
Treat paths and command arguments in JSON as potentially sensitive. Downstream services should set reasonable size and nesting limits and should not interpret arbitrary string values as filenames, shell commands or HTML. A valid JSON document can still contain unsafe content for a careless consumer.
Common mistakes
- Expecting NaN or infinity literals instead of
null. - Depending on pretty-print whitespace or object-key order.
- Ignoring unit or semantic changes because keys still parse.
- Passing strings from JSON directly to a shell.
Checklist
- Validate keys, types, ranges, units and nullability.
- Pin the producing nlmx version and expected schema.
- Use parsed-value tests for semantics and hashes for archive integrity.
- Review path and command metadata before external sharing.
Further reading
See CSV conventions, manifests and checksums and reproducibility levels.