Skip to main content

JSON, TOML and YAML

There is really not much to say about these parsers, except that they are very commonly used and have no special configuration options. They map between JavaScript object and primitives and byte streams.

Worth mentioning is that YAML files may actually contain multiple ----separated YAML documents. All YAML documents may be accessed via the FIELDS array, as specified by the WithFields interface.

FormatMain Media TypeParser
JSONapplication/jsonJSONParser
TOMLapplication/tomlTOMLParser
YAMLapplication/yamlYAMLParser
import { Parser, URI } from '@divine/uri`;

const json = await new URI('file.json').load();
await new URI('file.yaml').save();

const tomlString = (await Parser.serializeToBuffer(json, 'application/toml')).toString();