Documentation
¶
Overview ¶
Package jsonjs reads and writes JSON as JavaScript's JSON.parse and JSON.stringify do, for files this toolkit shares with the TypeScript CLI, such as cdk.context.json.
JavaScript differs from encoding/json in three ways that show in a file:
- An object's keys come in JavaScript's order: integer-like keys first, in ascending numeric order, then the rest in insertion order.
- A duplicate key keeps its first position and takes its last value.
- Numbers are written in JavaScript's form, so 1.0 is written 1 and 1e2 is written 100.
Strings are written as JSON.stringify writes them, except that a lone UTF-16 surrogate escape becomes U+FFFD, where JavaScript keeps the escape.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Format ¶
Format returns v as JSON.stringify(JSON.parse(v), undefined, 2) writes it, with no final newline.
func Merge ¶
Merge returns src merged into dst, as upstream's deepMerge merges a later settings layer into an earlier one. When both are objects, their members merge recursively; otherwise src replaces dst.
func Order ¶
Order returns keys, given in insertion order, in the order JavaScript gives an object's keys: integer-like keys first, in ascending order, then the others in insertion order.
Types ¶
type Object ¶
type Object struct {
// contains filtered or unexported fields
}
Object is a JSON object, with its members in JavaScript's order. The zero value is an empty object.
func ParseObject ¶
ParseObject parses b, which must hold a JSON object, as JSON.parse would.
func (*Object) Format ¶
Format returns the object as JSON.stringify(o, undefined, 2) writes it, followed by a newline when newline is set.