I have been looking at JSONPath and though it seems pretty well done, I wonder if anyone has worked with it and can comment on its usability, or can recommend alternatives? What would be really slick is if there was a plugin for JQuery that did something like this. I have been searching the plugins and coming up empty handed. Anyway, before I spend time getting to know JSONPath (which has some aspects I am not keen on), or before I reinvent wheels, I thought I'd see if anyone had an angle on this...
To give you an idea what I mean, imagine this Javascript object:
var Characters=[
{
id: "CuriousGeorge",
species:"Monkey",
mood: "curious",
appendage: [
{
type: "hand",
side: "left",
holding: [
{ id: "Banana" }
]
},
{
type: "hand",
side: "right",
holding: []
},
{
type: "foot",
side: "left",
holding: []
},
{
type: "foot",
side: "right",
holding: [
{ id: "YellowHat" },
{ id: "Keys" }
]
}
]
},
{
id: "ManInYellowHat",
species: "Human",
mood: "angry",
//...ok, you get it...
}
]
Wouldn't it be great to get to of some of the deeper objects by something like Jquery selectors?
var banana=SomeUtility("Characters holding #Banana").get(0);
var leftHands=SomeUtility("Characters appendage[type=hand][side=left]").get();
(This may qualify for worlds corniest code example, but hey, my kids just watched this. And I can't use real example because of NDA...)
...And, to make it more interesting, if I were to create such a thing, would anyone use it?
JSONPath is a query language for JSON, similar to XPath for XML. XPath expression can be used to extract information from an XML document by evaluating given expression.
JSONPath is a query language for JSON, similar to XPath for XML. It allows you to select and extract data from a JSON document. You use a JSONPath expression to traverse the path to an element in the JSON structure.
Jayway JsonPath is a Java port of Stefan Goessner JsonPath implementation.
Check out JSON Select - CSS-like selectors for JSON.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With