Categorygithub.com/elliotcourant/jsonpath
modulepackage
0.0.0-20201008003839-dcb0e085768f
Repository: https://github.com/elliotcourant/jsonpath.git
Documentation: pkg.go.dev

# README

jsonpath

PkgGoDev Build Status codecov

Go implementation of jsonpath

This is still a work in progress, updates to come.

Example

const jsonString = `{
  "firstName": "John",
  "lastName" : "doe",
  "age"      : 26,
  "address"  : {
    "streetAddress": "naist street",
    "city"         : "Nara",
    "postalCode"   : "630-0192"
  },
  "phoneNumbers": [
    {
      "type"  : "iPhone",
      "number": "0123-4567-8888"
    },
    {
      "type"  : "home",
      "number": "0123-4567-8910"
    },
    {
      "type"  : "mobile",
      "number": "0913-8532-8492"
    }
  ]
}`

result, err := Jsonpath([]byte(jsonString), "$.phoneNumbers[*].type")
if err != nil {
    log.Fatal(err)
}

for _, item := range result {
    fmt.Println(item)
}
// Output:
// iPhone
// home
// mobile

Supported operations

There are still a few operations which this library does not support but the goal is to support all of these path operations.

OperationSupportedDescription
$YesThe root object/element.
@NoThe current object/element. (To be added).
. or []YesChild operator. Within [] single quotes or double quotes can be used.
..YesRecursive decent.
*YesWildcard. All objects/elements regardless of their names.
[]Yessubscript operator. XPath uses it to iterate over element collections and for predicates. In Javascript and JSON it is the native array operator.
[,]YesUnion operator in XPath results in a combination of node sets. JSONPath allows alternate names or array indices as a set.
[start:end:step]NoArray slice operator borrowed from ES4. (To be added).
?()NoApplies a filter (script) expression. (To be added).
()NoScript expression, using the underlying script engine. (To be added).

# Functions

Jsonpath will evaluate the provided jsonpath on the provided json.
NewEvaluator will compile the provided jsonpath and create an object that can run that expression on provided json objects.

# Structs

No description provided by the author