GithubHelp home page GithubHelp logo

isabella232 / jsonpath-1 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dolthub/jsonpath

0.0 0.0 0.0 63 KB

golang jsonpath library. follow the majority rules in this article http://goessner.net/articles/JsonPath/

License: MIT License

Go 100.00%

jsonpath-1's Introduction

JsonPath

Build Status

A golang implementation of JsonPath syntax. follow the majority rules in http://goessner.net/articles/JsonPath/ but also with some minor differences.

this library is till bleeding edge, so use it at your own risk. :D

Golang Version Required: 1.5+

Get Started

go get github.com/oliveagle/jsonpath

example code:

import (
    "github.com/oliveagle/jsonpath"
    "encoding/json"
)

var json_data interface{}
json.Unmarshal([]byte(data), &json_data)

res, err := jsonpath.JsonPathLookup(json_data, "$.expensive")

//or reuse lookup pattern
pat, _ := jsonpath.Compile(`$.store.book[?(@.price < $.expensive)].price`)
res, err := pat.Lookup(json_data)

Operators

referenced from github.com/jayway/JsonPath

Operator Supported Description
$ Y The root element to query. This starts all path expressions.
@ Y The current node being processed by a filter predicate.
* X Wildcard. Available anywhere a name or numeric are required.
.. X Deep scan. Available anywhere a name is required.
. Y Dot-notated child
['' (, '')] X Bracket-notated child or children
[ (, )] Y Array index or indexes
[start:end] Y Array slice operator
[?()] Y Filter expression. Expression must evaluate to a boolean value.

Examples

given these example data.

{
    "store": {
        "book": [
            {
                "category": "reference",
                "author": "Nigel Rees",
                "title": "Sayings of the Century",
                "price": 8.95
            },
            {
                "category": "fiction",
                "author": "Evelyn Waugh",
                "title": "Sword of Honour",
                "price": 12.99
            },
            {
                "category": "fiction",
                "author": "Herman Melville",
                "title": "Moby Dick",
                "isbn": "0-553-21311-3",
                "price": 8.99
            },
            {
                "category": "fiction",
                "author": "J. R. R. Tolkien",
                "title": "The Lord of the Rings",
                "isbn": "0-395-19395-8",
                "price": 22.99
            }
        ],
        "bicycle": {
            "color": "red",
            "price": 19.95
        }
    },
    "expensive": 10
}

example json path syntax.

jsonpath result
$.expensive 10
$.store.book[0].price 8.95
$.store.book[-1].isbn "0-395-19395-8"
$.store.book[0,1].price [8.95, 12.99]
$.store.book[0:2].price [8.95, 12.99, 8.99]
$.store.book[?(@.isbn)].price [8.99, 22.99]
$.store.book[?(@.price > 10)].title ["Sword of Honour", "The Lord of the Rings"]
$.store.book[?(@.price &lt; $.expensive)].price [8.95, 8.99]
$.store.book[:].price [8.9.5, 12.99, 8.9.9, 22.99]
$.store.book[?(@.author =~ /(?i).*REES/)].author "Nigel Rees"

Note: golang support regular expression flags in form of (?imsU)pattern

jsonpath-1's People

Contributors

bheni avatar creepfmd avatar kellrott avatar oliveagle avatar superfell avatar tolleiv avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.