Documentation
¶
Overview ¶
Package jsonlayout edits the top-level members of a JSON object in place, keeping the bytes and the layout (indentation, one line or many, the text between a name and its value) of everything it does not change. DataTug project files live in Git repositories: a write that changes one value must change only the lines of that value.
Index ¶
Constants ¶
const DefaultIndent = "\t"
DefaultIndent is the indentation of an object that has no member to take it from, as the project store writes JSON.
Variables ¶
This section is empty.
Functions ¶
func Equal ¶
Equal reports whether a and b, valid JSON, hold the same value: member order, whitespace, string escapes and the spelling of a number do not matter.
func IndentOf ¶
IndentOf is the unit of indentation of body, valid JSON: the leading whitespace of its first indented line, or "" when body is on one line.
func Merge ¶
Merge makes the object existing hold exactly the members of want, in place. A member whose value is Equal to the one wanted keeps its bytes; a changed one has only its value rewritten, in the object's layout; one that is not wanted is removed, and so is a second member of the same name. The members existing lacks are appended in the order of order (names not in want are skipped). It is false when existing is not an object.
Types ¶
type Layout ¶
type Layout struct {
Indent, Unit, Colon string
// Newline is "\r\n" in a file that ends its lines so, else "\n".
Newline string
}
Layout is how an object lays out its members: the whitespace before a member name ("" when the object is on one line), the unit of indentation of nested values, and the text between a name and its value.
type Object ¶
Object is the top level of a JSON object as its bytes stand.
func Scan ¶
Scan locates the members of body, a valid JSON value. It is false when body is not an object.