A JSON5 parser implemented as an mq module.
- Single-line comments (
//) and block comments (/* */) - Single-quoted strings
- Unquoted identifiers as object keys
- Trailing commas in objects and arrays
- Hexadecimal numbers (
0xFF) Infinity,-Infinity,NaN- Unicode and hex escape sequences in strings (
\uXXXX,\xXX)
Copy json5.mq to your mq module directory, or place it anywhere and reference it with -L.
cp json5.mq ~/.local/mq/config/mq -L /path/to/modules -I raw \
'import "json5" | json5::json5_parse(.)' input.json5If you copied it to the mq built-in module directory:
mq -I raw 'import "json5" | json5::json5_parse(.)' input.json5Parses a JSON5 string and returns the corresponding mq value.
| Input type | Output |
|---|---|
| String | Parsed JSON5 value (object, array, string, number, bool, or None) |
Raises an error if the input is not valid JSON5.
Given config.json5:
{
// Server configuration
host: 'localhost',
port: 8080,
debug: true,
tags: ['web', 'api',], // trailing comma is fine
limits: {
maxRetries: 0xFF, // hex number
timeout: 30.5e3,
},
}mq -L . -I raw 'import "json5" | json5::json5_parse(.) | ."host"' config.json5
# => "localhost"
mq -L . -I raw 'import "json5" | json5::json5_parse(.) | ."limits"."maxRetries"' config.json5
# => 255Requires mq v0.5 or later.
MIT