Documentation
¶
Overview ¶
Package jsonedit makes minimal text edits to a JSON document: it finds the value at a path and replaces, inserts or deletes it while every other byte of the document stays as it was, including indentation, key order and line ends. It is the Go counterpart of the VSCode extension's jsonc-parser "modify" (src/docEdits.ts), so a file edited by a tool and by the editor shows the same small diff.
A path is a list of steps: a string selects the member of an object, an int the element of an array. The document must be valid JSON without comments. Values passed in are JSON text; they are laid out in the document's style: in one line (`{"a": 1, "b": 2}`) where the value they replace or the container they enter is on one line, else spread over lines with the document's own indentation. The package imports the standard library only.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNotFound = errors.New("jsonedit: no value at path")
ErrNotFound is returned (wrapped) when a path leads to nothing.
Functions ¶
func Delete ¶
Delete removes the object member or array element at path, with its comma, and returns doc. The path must exist and not be empty.
func Insert ¶
Insert adds value as element index of the array at path; index -1 or the array's length appends.
func Set ¶
Set puts value at path: it replaces the value when the path exists, else it adds the missing object member (and the missing objects above it, when the path is deeper) at the end of the nearest existing object, or appends to an array when the last step is an index equal to the array's length.