{"modulePath":"github.com/weakpixel/engine","version":"v0.0.0-20261205071607-94fff0387040","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package jsonedit\n\nPackage 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.\n\nA 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.\n\n## Variables\n\n```go\nvar ErrNotFound = errors.New(\"jsonedit: no value at path\")\n```\nErrNotFound is returned (wrapped) when a path leads to nothing.\n\n## Functions\n\n```go\nfunc Delete(doc []byte, path ...any) ([]byte, error)\n```\nDelete removes the object member or array element at path, with its comma, and returns doc. The path must exist and not be empty.\n\n```go\nfunc Insert(doc, value []byte, index int, path ...any) ([]byte, error)\n```\nInsert adds value as element index of the array at path; index -1 or the array's length appends.\n\n```go\nfunc Replace(doc, value []byte, path ...any) ([]byte, error)\n```\nReplace returns doc with the value at path replaced by value. The path must exist.\n\n```go\nfunc Set(doc, value []byte, path ...any) ([]byte, error)\n```\nSet 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.\n\n## Types\n\n```go\ntype Span struct{ Start, End int }\n```\nSpan is the byte range \\[Start, End) of a value in a document.\n\n```go\nfunc Find(doc []byte, path ...any) (Span, error)\n```\nFind returns the span of the value at path. The empty path is the whole document value.\n\n","path":"github.com/weakpixel/engine/jsonedit","name":"jsonedit","synopsis":"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.","isRedistributable":true}
