You do not need to use jQuery. Simple JavaScript will work. I would not recommend any library that portes XML standards to JavaScript, and I was disappointed that there was no other solution for this, so I wrote my own library.
I adapted the regular expression to work with JSON.
First we contract the JSON object. Then you need to keep the starting and long matching substrings. For example:
"matched".search("ch")
For a JSON string, this works the same way (unless you explicitly look at the commas and braces, in which case I would recommend some preliminary conversion of your JSON object before executing the regular expression (ie think :, {,}).
Then you need to restore the JSON object. The algorithm I created does this by detecting the JSON syntax by recursively jumping back from the matching index. For example, a pseudo code might look like this:
find the next key preceding the match index, call this theKey then find the number of all occurrences of this key preceding theKey, call this theNumber using the number of occurrences of all keys with same name as theKey up to position of theKey, traverse the object until keys named theKey has been discovered theNumber times return this object called parentChain
Using this information, you can use a regular expression to filter a JSON object to return the key, value, and parent chain of objects.
You can see the library and code that I wrote at http://json.spiritway.co/
mikewhit Mar 28 '15 at 2:44 2015-03-28 02:44
source share