MCPcopy Create free account
hub / github.com/jmespath/go-jmespath

github.com/jmespath/go-jmespath @v0.4.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.4.0 ↗ · + Follow
1,255 symbols 5,237 edges 48 files 611 documented · 49% 227 cross-repo links updated 2y ago★ 62227 open issues

Browse by type

Functions 1,151 Types & classes 104
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

go-jmespath - A JMESPath implementation in Go

Build Status

go-jmespath is a GO implementation of JMESPath, which is a query language for JSON. It will take a JSON document and transform it into another JSON document through a JMESPath expression.

Using go-jmespath is really easy. There's a single function you use, jmespath.search:

> import "github.com/jmespath/go-jmespath"
>
> var jsondata = []byte(`{"foo": {"bar": {"baz": [0, 1, 2, 3, 4]}}}`) // your data
> var data interface{}
> err := json.Unmarshal(jsondata, &data)
> result, err := jmespath.Search("foo.bar.baz[2]", data)
result = 2

In the example we gave the search function input data of {"foo": {"bar": {"baz": [0, 1, 2, 3, 4]}}} as well as the JMESPath expression foo.bar.baz[2], and the search function evaluated the expression against the input data to produce the result 2.

The JMESPath language can do a lot more than select an element from a list. Here are a few more examples:

> var jsondata = []byte(`{"foo": {"bar": {"baz": [0, 1, 2, 3, 4]}}}`) // your data
> var data interface{}
> err := json.Unmarshal(jsondata, &data)
> result, err := jmespath.search("foo.bar", data)
result = { "baz": [ 0, 1, 2, 3, 4 ] }


> var jsondata  = []byte(`{"foo": [{"first": "a", "last": "b"},
                           {"first": "c", "last": "d"}]}`) // your data
> var data interface{}
> err := json.Unmarshal(jsondata, &data)
> result, err := jmespath.search({"foo[*].first", data)
result [ 'a', 'c' ]


> var jsondata = []byte(`{"foo": [{"age": 20}, {"age": 25},
                           {"age": 30}, {"age": 35},
                           {"age": 40}]}`) // your data
> var data interface{}
> err := json.Unmarshal(jsondata, &data)
> result, err := jmespath.search("foo[?age > `30`]")
result = [ { age: 35 }, { age: 40 } ]

You can also pre-compile your query. This is usefull if you are going to run multiple searches with it:

    > var jsondata = []byte(`{"foo": "bar"}`)
    > var data interface{}
    > err := json.Unmarshal(jsondata, &data)
    > precompiled, err := Compile("foo")
    > if err != nil{
    >   // ... handle the error
    > }
    > result, err := precompiled.Search(data)
    result = "bar"

More Resources

The example above only show a small amount of what a JMESPath expression can do. If you want to take a tour of the language, the best place to go is the JMESPath Tutorial.

One of the best things about JMESPath is that it is implemented in many different programming languages including python, ruby, php, lua, etc. To see a complete list of libraries, check out the JMESPath libraries page.

And finally, the full JMESPath specification can be found on the JMESPath site.

Extension points exported contracts — how you extend this code

browse all types & interfaces →

Core symbols most depended-on inside this repo

browse all functions →

Shape

Function 724
Method 427
Struct 64
Interface 21
FuncType 12
TypeAlias 7

Languages

Go100%

Modules by API surface

internal/testify/assert/assertions_test.go120 symbols
internal/testify/require/require_forward.go114 symbols
internal/testify/require/require.go114 symbols
internal/testify/assert/assertion_forward.go114 symbols
internal/testify/mock/mock_test.go109 symbols
internal/testify/assert/assertions.go83 symbols
internal/testify/require/requirements_test.go61 symbols
internal/testify/mock/mock.go59 symbols
internal/testify/assert/assertion_format.go57 symbols
internal/testify/suite/suite_test.go52 symbols
internal/testify/assert/forward_assertions_test.go48 symbols
functions.go43 symbols

For agents

$ claude mcp add go-jmespath \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page