Structured JSON
Operators that make complex JSON structures easy to read and write.
Action | Operator | Key/Value |
---|---|---|
Assign Value | <= |
Value |
Assign Defaults | << , >> |
Key |
Merge | << , >> |
Value |
Mixin | $ |
Key |
Conditional Defaults | <<? , >>? |
Key |
Use the update function for immutable updates.
Install
npm install structured-json
Import
Assign
let stores products = storesgroceryproducts // { milk }productsmilkstore // { products }
Assignment supports circular references, but it is up to you to be careful about infinite enumeration.
Merge
let products = products // { eggs: {}, // milk: {}, // kale: {}, // tofu: {} }
Defaults
When used in a key, the merge operator defines a default object for its siblings (>>
) or its parent (<<
):
let organicProducts veganProducts = organicProducts // { eggs: { organic }, // milk: { organic } }veganProducts // { kale: { vegan }, // tofu: { vegan } }
Define defaults for sibling child objects with successive merge operators (">> >>":
).
Mixin
A mixin is a variable meant only for referencing, and does not show up in enumeration.
let products = products // { milk: { color: "white" }, // kale: { color: "green" }, // tofu: { color: "white" } }
Conditionals
let products = products // { kale: { local: false } }
Update
let config = config =
The update
function uses immutability-helper
to create entirely new objects for each update.