Version: dev

to_json_compact

Stable function · Document I/O

Tier: stable · Kind: function · Topic: Document I/O

JuliaTypeScriptPythonRustGo
to_json_compacttoJsonCompactto_json_compactto_json_compactToJSONCompact

Julia

to_json_compact(file::EsmFile)
to_json_compact(file::EsmFile) -> String

The single-line wire form. Exists in every binding for call-site parity — Rust and Go have no default arguments and so cannot express to_json(file, indent=0).

In THIS binding it returns exactly what to_json returns, because JSON3 already emits the compact form (see to_json).

Source

TypeScript

function toJsonCompact(file: EsmFile, options?: ToJsonOptions): string

toJson with no indentation — the single-line wire form. Present in every binding, because Rust and Go have no default arguments and so cannot express toJson(file, { indent: 0 }).

Source

Python

to_json_compact(esm_file: EsmFile) -> str

to_json with no indentation — the single-line wire form.

Present in every binding, because Rust and Go have no default arguments and so cannot express to_json(file, indent=0).

Source

Example (to_json_compact)

compact = earthsci_ast.to_json_compact(doc)
assert "\n" not in compact and compact.startswith('{"esm":')
assert json.loads(compact) == json.loads(earthsci_ast.to_json(doc))

From docs/api/examples/python/documents.py

Rust

pub fn to_json_compact(esm_file: &EsmFile) -> Result<String, EsmError>

Serialize an ESM file to compact JSON string (no pretty printing)

This function is similar to to_json but produces compact JSON without extra whitespace, suitable for storage or transmission. It is a separate function rather than a to_json(file, opts) flag because Rust has no default arguments and a one-field options struct plus a to_json_with_options twin is heavier than the pair.

Arguments

  • esm_file - The ESM file to serialize

Returns

  • Ok(String) - Successfully serialized compact JSON string
  • Err(EsmError) - Serialization error

Source · Rust docs

Go

func ToJSONCompact(file *ESMFile) (string, error)

ToJSONCompact validates an ESM file and returns it as a compact canonical JSON string (no indentation). A separate function rather than a ToJSON option because Go has no default arguments.

Source · Go docs