-
Notifications
You must be signed in to change notification settings - Fork 680
How to find all parents elements in a JSON file
Source: StackOverflow
How to find all parents elements in a Json file? I'm currently working on a recursive menu which is built on top of jQuery which looks quite good already. The structure of the JSon file containing the menu looks as the following:
``js [ { "Id": "menuOfficeWebControlsForWebApplication", "Title": "Office Web Controls", "Resource": "/Documentation/Data/index.html" }, { "Id": "menuGettingStarted", "Title": "Getting Started", "Resource": "/Documentation/Data/getting-started.html", "Categories": [{ "Id": "menuCompilingFromSource", "Title": "Compiling From Source", "Resource": "/Documentation/Data/Getting-Started/compiling-from-source.html" },{ "Id": "menuDownloadReleasePackage", "Title": "Download Release Package", "Resource": "/Documentation/Data/Getting-Started/downloading-release-package.html" },{ "Id": "menuBuildingYourFirstApplication", "Title": "Building your first application", "Resource": "/Documentation/Data/Getting-Started/building-your-first-application.html" }] } ]
Now, I want to retrieve all the elements which are at a higher level and all the items which are directly below that item.
You can do it with AlaSQL SEARCH operator:
var res = alasql('SEARCH /(Categories/)? WHERE(Id) FROM ?', [data]);
To list only valid keys you can use:
var res = alasql('SEARCH /(Categories/)? Id FROM ?', [data]);
© 2014-2024, Andrey Gershun & Mathias Rangel Wulff
Please help improve the documentation by opening a PR on the wiki repo