package jsonimport ()// CreatePath creates JSON Path.//// JSON Path rule// $ : root object or element. The JSON Path format must start with this operator, which refers to the outermost level of the JSON-formatted string.// . : child operator. You can identify child values using dot-notation.// .. : recursive descent.// [] : subscript operator. If the JSON object is an array, you can use brackets to specify the array index.// [*] : all objects/elements for array.//// Reserved words must be properly escaped when included in Path.//// Escape Rule// single quote style escape: e.g.) `$['a.b'].c`// double quote style escape: e.g.) `$."a.b".c`func ( string) (*Path, error) { , := decoder.PathString().Build()if != nil {returnnil, }return &Path{path: }, nil}// Path represents JSON Path.typePathstruct { path *decoder.Path}// RootSelectorOnly whether only the root selector ($) is used.func ( *Path) () bool {return .path.RootSelectorOnly}// UsedSingleQuotePathSelector whether single quote-based escaping was done when building the JSON Path.func ( *Path) () bool {return .path.SingleQuotePathSelector}// UsedSingleQuotePathSelector whether double quote-based escaping was done when building the JSON Path.func ( *Path) () bool {return .path.DoubleQuotePathSelector}// Extract extracts a specific JSON string.func ( *Path) ( []byte, ...DecodeOptionFunc) ([][]byte, error) {returnextractFromPath(, , ...)}// PathString returns original JSON Path string.func ( *Path) () string {return .path.String()}// Unmarshal extract and decode the value of the part corresponding to JSON Path from the input data.func ( *Path) ( []byte, interface{}, ...DecodeOptionFunc) error { , := extractFromPath(, , ...)if != nil {return } := make([]interface{}, 0, len())for , := range {varinterface{}if := Unmarshal(, &); != nil {return } = append(, ) }if := decoder.AssignValue(reflect.ValueOf(), reflect.ValueOf()); != nil {return }returnnil}// Get extract and substitute the value of the part corresponding to JSON Path from the input value.func ( *Path) (, interface{}) error {return .path.Get(reflect.ValueOf(), reflect.ValueOf())}
The pages are generated with Goldsv0.8.2. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.