Skip to content

jsonqueryvsjsonlite

MIT 3 1 250
58.1 thousand (month) Oct 15 2019 v1.3.5(21 days ago)
373 2 118 MIT
Dec 03 2013 1.2 million (month) 1.8.8(1 year, 16 days ago)

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.

A reasonably fast JSON parser and generator, optimized for statistical data and the web. Offers simple, flexible tools for working with JSON in R, and is particularly powerful for building pipelines and interacting with a web API.

In addition to converting JSON data from/to R objects, 'jsonlite' contains functions to stream, validate, and prettify JSON data. The unit tests included with the package verify that all edge cases are encoded and decoded consistently for use with dynamic data in systems and applications.

Example Use


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"
}
library("jsonlite")

json <- '["Mario", "Peach", null, "Bowser"]'

# load json to dataframe/array/matrix (determined automatically)
fromJSON(json)

Alternatives / Similar


Was this page helpful?