Skip to content

jmespathvsjsonquery

MIT 63 3 2,424
507.7 million (month) Feb 09 2022 1.1.0(2026-01-22 16:35:24 ago)
276 1 6 MIT
Oct 15 2019 58.1 thousand (month) v1.3.7(2026-03-30 06:38:20 ago)

JMESPath (pronounced “james path”) allows you to declaratively specify how to extract elements from a JSON document.

In web scraping, jmespath is a powerful tool for parsing and reshaping large JSON datasets. Jmespath is fast and easily extendible following it's own powerful query language.

For more see the Json parsing introduction section.

jsonquery is a Go library that allows you to parse and extract data from JSON documents using JSONPath expressions. JSONPath is similar to XPath, but it is designed specifically for working with JSON documents.

The jsonquery library allows you to traverse the JSON tree structure and extract values using JSONPath expressions. It provides a simple and intuitive API for querying the JSON data, and it is built on top of the popular jsoniter library.

Example Use


```python import jmespath data = { "data": { "info": { "products": [ {"price": {"usd": 1}, "_type": "product", "id": "123"}, {"price": {"usd": 2}, "_type": "product", "id": "345"} ] } } } # easily reshape nested dataset to flat structure: jmespath.search("data.info.products[*].{id:id, price:price.usd}", data) [{'id': '123', 'price': 1}, {'id': '345', 'price': 2}] ```
```go package main import ( "fmt" "log" "github.com/antchfx/jsonquery" ) func main() { // Parse the JSON string doc, err := jsonquery.Parse([]byte(` { "name": "John Doe", "age": 30, "address": { "street": "Main St", "city": "Anytown", "state": "CA", "zip": "12345" }, "phones": [ "555-555-5555", "555-555-5556" ] } `)) if err != nil { log.Fatal(err) } // Extract the name name := jsonquery.FindOne(doc, "name") fmt.Println(name.InnerText()) // "John Doe" // Extract the city city := jsonquery.FindOne(doc, "address.city") fmt.Println(city.InnerText()) // "Anytown" // Extract all phone numbers phones := jsonquery.Find(doc, "phones[*]") for _, phone := range phones { fmt.Println(phone.InnerText()) } // "555-555-5555" // "555-555-5556" } ```

Alternatives / Similar


Was this page helpful?