modulepackage
0.0.0-20200629203448-1a936bd500cf
Repository: https://github.com/sourcegraph/jsonx.git
Documentation: pkg.go.dev
# README
jsonx
Package jsonx is an extended JSON library for Go. It is highly tolerant of
errors, and it supports trailing commas and comments (//
and /* ... */
).
It is ported from Visual Studio Code's comment-aware JSON parsing and editing APIs in TypeScript, specifically in these files:
Status: Experimental
- Where the original TypeScript code's API is not idiomatic in Go, this library does not (yet) attempt to provide an idiomatic Go API. This is mainly evident in the error return API for parsing and scanning errors.
# Functions
ApplyEdits applies the edits to the JSON document and returns the edited document.
ComputePropertyEdit returns the edits necessary to set the value at the specified key path to the value.
ComputePropertyRemoval returns the edits necessary to remove the property at the specified key path.
FindNodeAtLocation returns the node with the given key path under the JSON document parse tree root.
Format returns edits that format the entire JSON document according to the format options.
FormatEdit returns the edits necessary to perform the original edit for maintaining the formatting of the JSON document.
FormatRange returns edits that format the JSON document (starting at the character offset and continuing for the character length) according to the format options.
MakePath returns a Path consisting of the specified components, each of which may be either a string (which is treated as a property segment) or an int (which is treated as an array index).
NewScanner creates a new scanner for the JSON document.
NodeValue returns the JSON parse tree node's value.
ObjectPropertyNames returns property names of the JSON object represented by the specified JSON parse tree node.
Parse the given text and returns the standard JSON representation of it, excluding the extensions supported by this package (such as comments and trailing commas).
ParseTree parses the given text and returns a tree representation the JSON content.
No description provided by the author
PropertyPath returns a Path consisting of the specified property names.
Walk parses the JSON document text and calls the visitor's funcs for each object, array and literal reached.
# Constants
JSON node types.
Syntax kinds.
JSON node types.
Parse error codes.
Syntax kinds.
Parse error codes.
Syntax kinds.
Parse error codes.
Syntax kinds.
Parse error codes.
Syntax kinds.
Parse error codes.
Syntax kinds.
Syntax kinds.
Scan error codes.
Parse error codes.
Scan error codes.
Parse error codes.
A catch all for an unexpected ScanErrorCode.
Parse error codes.
Scan error codes.
Syntax kinds.
Syntax kinds.
Scan error codes.
JSON node types.
Syntax kinds.
JSON node types.
Syntax kinds.
JSON node types.
Syntax kinds.
Syntax kinds.
Parse error codes.
Parse error codes.
Parse error codes.
These get the ugly ParseError prefix because they conflict with existing ScanErrorCode constants, and the ScanErrorCode constants existed first, so we can't change them for BC reasons.
Parse error codes.
Parse error codes.
JSON node types.
Parse error codes.
JSON node types.
Syntax kinds.
Syntax kinds.
Syntax kinds.
Scan error codes.
Scan error codes.
Scan error codes.
Syntax kinds.
Parse error codes.
# Structs
An Edit represents an edit to a JSON document.
FormatOptions specifies formatting options.
Node represents a node in a JSON document's parse tree.
No description provided by the author
ParseOptions specifies options for JSON parsing.
A Scanner scans a JSON document.
ScanOptions specifies options for NewScanner.
A Segment is a component of a JSON key path.
A Visitor has its funcs invoked by Walk as it traverses the parse tree of a JSON document.
# Type aliases
NodeType is the type of a JSON node.
A ParseErrorCode is a category of error that can occur while parsing a JSON document.
A Path is a JSON key path, which describes a path from an ancestor node in a JSON document's parse tree to one of its descendents.
A ScanErrorCode is a category of error that can occur while scanning a JSON document.
A SyntaxKind is a kind of syntax element in a JSON document.