FSON (Flexible Serialized Object Notation) is an extension for JSON that is used primarily for configuration. The user can quickly configure the configuration using references or a template strings.
/* Multiline comment */ [null, NaN, Infinity, -Infinity, 0x1ABC /*Hexadecimal*/] // Single comment
- You can use identifiers without quotes and with single quotes:
{
"double quotes": null,
'single quotes': null,
withoutQuotes: null
}
- A reference is an object that can be anywhere (it can be either a pair of an object or it can be in an array) that can be referenced using it's identifier or path. For example:
{
something: {
key: #{ #id: "identifier"; #value: "value"; }
}
}
- The reference in the example above can be referenced in two ways:
- Using it's identifier:
#identifier
or#"identifier"
- Using it's path:
#/something/identifier
or#/"something"/"identifier"
- Using it's identifier:
- Template strings are strings enclosed in backticks. They allow you to
embed other values (including references) in them using
${value}
. For example:{ x: 5, something: `x is ${x}` }
- Objects and arrays can have a trailing comma:
{ x: { y: [], }, }
- Numbers can start with a plus:
+1.5
- Strings can be multiline:
"hello
world"
- Whitespaces don't matter
See all examples in Examples directory.
How to run example:
cargo run --example EXAMPLE_NAME
FSON is already ready for compilation to WebAssembly and already has the
necessary functions. js-sys
and wasm-bindgen
libraries and functions are
used only when compiling to WebAssembly.
Use these commands to compile
to wasm:
# Install wasm-pack
cargo install wasm-pack
# Compile to wasm
wasm-pack build --target web
JavaScript example
import init, { parse, stringify } from "./jsonparser.js";
init().then(() => {
console.log(stringify({
// Creating reference
x: {
"#id": "test",
"#value": "value",
},
// Using reference
y: [
// Identifier
{ "#reference_id": "test" },
// Path
{ "#reference_path": ["x"] },
// Template string
{
"@template_string": [
"test is ",
{ "#reference_id": "test" }, /* Reference */
"; 2 + 2 = ",
4, /* Normal value */
],
},
],
}));
});
MIT