This is a collection of functions for parsing text formats.
@parse/json(text)
Parses the indicated text as JSON using the JavaScript JSON.parse() method.
@parse/yaml(text)
Parses the indicated text as JSON or YAML. The parsed plain JavaScript object is returned or, if the parse fails, this returns undefined
. This can be used to parse JSON or YAML files.
Parsing a quoted argument on the command line:
$ ori @parse/yaml "'[1, 2, 3]'"
- 1
- 2
- 3
This is similar to the @tree/plain function, but that can only parse JSON/YAML representing trees. In contrast, the @parse/yaml
function can handle text representing things that aren’t trees, such as arrays, dates, and numbers.