One of the strengths of CSS and jQuery is that it provides a common and powerful mechanism known as a selector language for referencing bits of data, especially data whose structure is not exactly known at runtime which makes such an addressing scheme a perfect fit for the often lumpy world of HTML.
Increasingly JSON is being used as a transport medium for data and with the rise of NoSQL solutions, having a selector language for JSON makes a lot of sense when dealing with JSON documents whose structure isn’t deterministic.
JSONSelect provides a good implementation of just such a JSON selector language but after working with it on a project I found myself needing to do more than it allowed me to do. Namely, I wanted 1. to be able to perform a selection and receive matching paths instead of the data contained in those paths and I wanted 2. to be able to modify data specified at a path location in-place.
jsonselect.match(sel, obj, asPath); // Added the asPath flag to return a path instead of the values jsonselect.forEach(sel, obj, fun, asPath); // Added the same flag to forEach, I use this to jsonselect.get(path,obj); // For getting the value using a path jsonselect.set(path, value, obj); // For setting the value of a path jsonselect.del(path,root); // For deleting a path
Here is my modified version of jsonselect in case anyone needs help solving the same problems I mentioned above.