Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Any idea on supporting JsonPath? #112

Closed
renkun-ken opened this issue Oct 8, 2015 · 8 comments
Closed

Any idea on supporting JsonPath? #112

renkun-ken opened this issue Oct 8, 2015 · 8 comments

Comments

@renkun-ken
Copy link

Sometimes it is super convenient to use XPath-like query to query data in a json, like what JsonPath does. Any idea on supporting this?

@jeroen
Copy link
Owner

jeroen commented Oct 8, 2015

Unless there is a simple C implementation available, I think it would be easier to do this in a separate package.

@renkun-ken
Copy link
Author

Sadly it seems no C-implementation of JPath is available at the moment.

@jeroen
Copy link
Owner

jeroen commented Oct 8, 2015

Are you aware of jq and jqr ?

@renkun-ken
Copy link
Author

Thanks for your links! I'll take a look at it :)

@timelyportfolio
Copy link

There's always V8 for the various JavaScript libraries. I have a list somewhere of JavaScript Xpath-like libraries that I put together at some point. @renkun-ken, would that be helpful?

@renkun-ken
Copy link
Author

Thanks @timelyportfolio! Would you like to provide some example?

@renkun-ken renkun-ken reopened this Oct 8, 2015
@timelyportfolio
Copy link

Have not found my list yet, but I remember this one https://github.com/s3u/JSONPath and https://github.com/PencilCode/jsonql. There is also this StackOverflow post (out of date).. I'll try to work up an example in R/V8.

@timelyportfolio
Copy link

An example in R:

library(V8)

ctx <- new_context(global = "window")
ctx$source(
  "https://rawgit.com/s3u/JSONPath/master/lib/jsonpath.js"
)
ctx$eval(
'
var books = {
"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
  }
}
}
'
)

ctx$get('JSONPath({json:books,path: "$..book[?(@.price<10)]"})')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants