Javascript query of JSON data file

Posted on 2013-10-05
Medium Priority
Last Modified: 2013-11-30
Actually my original question was answered by Alexcode in a post named "XML query in Javascript"  I have a follow up question and didn't know if it could be viewed in the original post since it's closed.   As such the javascript that Alex presented is noted there.. Works wonderfully.   Please read it for the context of my follow up question..

I want to return multiple values of the query result.  If I query by "i" which is airport id I also want to return the "n" airport name and "t" and "g" the lat/long values.   I'm not sure how to do this.

Additionally, I want to move the JSON file to be external to the script.  How does this get named and also how do I reference the external JSON file from within the actual script doing the lookup

Thank you in advance for your input...
Question by:aviator21114
  • 3
  • 2

Author Comment

ID: 39549793
Thank you for including the link for me.  I was in a hurry and didn't take the time to figure out how to do this... Apologies...
LVL 26

Accepted Solution

Eddie Shipman earned 2000 total points
ID: 39552428
I use a library called JSONPath. It allows you to use XPath queries on your JSON data:


An example of how to find the airport data based on the ID would look something like the code in this fiddle:

To move your JSON data into an external file just name it and include it in a script tag.
Assign your JSON data to a variable and it will be available in your unit if you add the link to the file before the link to your unit. i.e.
<script type="text/javascript" src="externalJSON.js"></script>
<script type="text/javascript" src="MyUnit.js"></script>

Open in new window

LVL 26

Expert Comment

by:Eddie Shipman
ID: 39552522
I update the fiddle to show how to have external data.

Author Comment

ID: 39578160
Eddie... Apologies, I didn't see that you had posted to my question...  Let me take a look at this and digest it..

Thank you,
LVL 26

Expert Comment

by:Eddie Shipman
ID: 39676120
Cleaning up after just a little over a month?

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

624 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question