Version: dev

load_document

Stable function · Document I/O

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

JuliaTypeScriptPythonRustGo
load_documentloadDocumentload_documentload_documentLoadDocument

Julia

load_document(doc::AbstractDict; base_path, metaparameters)
load_document(doc::AbstractDict; base_path=nothing, metaparameters=Dict{String,Int}()) -> EsmFile

Parse an ESM document held in memory as a native Julia dict — the same document a .esm file holds, just already parsed. Runs the identical pipeline load_path runs (top-level {ref} inlining, schema validation, expression-template lowering, coercion, subsystem-ref resolution); base_path anchors the relative refs a file input anchors at its own directory, and defaults to pwd() for that. Left at nothing the document has no location of its own, so a relative coupling_import ref resolves against flatten’s own base_path instead (esm-spec §10.10 -> §4.7).

Distinct from coerce_esm_file, which only coerces: it does not validate, and it leaves a {ref} subsystem as an unresolved SubsystemRef that flatten then SKIPS — so a dict must come through here, not through coerce_esm_file, before it is flattened and run.

Source

TypeScript

function loadDocument(doc: object, options?: LoadOptions): EsmFile

Parse an ESM document that is ALREADY a JavaScript object — the same document a .esm file holds, just already JSON.parsed.

options.canonical has no effect here: canonical mode tags numeric literals during JSON decoding, and this entry point does no decoding. Callers who want tagged leaves should pass the JSON text to loadString with canonical: true instead.

Parameters

  • doc — The already-parsed document
  • options — Optional load-time settings (see LoadOptions )

Returns

Typed EsmFile object

Throws

Source

Python

load_document(document: dict, *, metaparameters: dict[str, int] | None = None, base_path: str | os.PathLike[str] | None = None) -> EsmFile

Parse an ESM document that is ALREADY a Python dict — the same document a .esm file holds, just already json.loaded.

Parameters

  • document (dict) — The already-parsed document.

Source

Example (load_document)

raw = json.loads(text)
from_dict = earthsci_ast.load_document(raw)
assert from_dict.metadata.name == "Decay"

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

Rust

pub fn load_document(document: &Value) -> Result<EsmFile, EsmError>

Load and parse an ESM document that is ALREADY parsed as a serde_json::Value — the same document a .esm file holds, just already decoded. Runs the identical pipeline load_string runs (subsystem-ref resolution, version gates, schema validation, §9.7 template machinery, typed deserialization).

Source · Rust docs

Go

func LoadDocument(document map[string]any, opts ...LoadOption) (*ESMFile, error)

LoadDocument parses an ESM document that is ALREADY decoded into a Go map — the same document a .esm file holds, just already unmarshalled. It runs the identical pipeline LoadString runs.

One thing it CANNOT recover is declaration order: a map

\[string\]

any has none, and re-encoding it writes the keys sorted. A document loaded this way therefore flattens with sorted-name order wherever esm-libraries-spec §4.7.5 step 4 asks for document order. Use LoadPath / LoadString when the order matters.

Source · Go docs