parse JSON from Ajax pull in JQUERY

Posted on 2012-09-15
Last Modified: 2012-09-16

I have a large JSON with 30 elements coming back as a JSON array via JQUERY:

                 url: '../../services/markers.php',
                 method: "get",
                 dataType: 'json',
                 data: 'name='+name+'&loc='+loc+'&range='+range+'&filter1='+filter1+'&filter2='+filter2,
                 success: function(Markerdata, status, xhr) {
                              Do task 1
                              Do task 2


A typical result:

"ID" :      "3266",
"ProviderID" :      "360159",
"Address" :      "272 HOSPITAL ROAD",
"City" :      "CHILLICOTHE",
"St" :      "OH",
"ZIP" :      "45601",
"County" :      "ROSS",
"PhnNum" :      "7407797358",
"Type" :      "Acute Care Hospitals",
"Owner" :      "Voluntary non-profit - Private",
"ER" :      "true",
"Lat" :      "39.395330000",
"Lng" :      "-82.970539000",
"Tier1or2" :      "1",
"Academic" :      "0",
"Cmpsn200plus" :      "1",
"CME" :      "0",
"MjDblCvg" :      "0",
"MdLvlCvg" :      "1",
"EMR" :      "0",
"NoIHCdCvg" :      "0",
"NoAdmOrdrs" :      "1",
"PriSnglCvg" :      "1",
"AnyStLic" :      "1",
"RecStatus" :      "1",
"Reprentation" :      "1",
"OtherInfo" :      "",
"data" :      "<h2>ADENA REGIONAL MEDICAL CENTER</h2><p>272 HOSPITAL ROAD<br />CHILLICOTHE, OH 45601<br />(740) 779-7358<br /><button ID=&quot;3266&quot;>See More Information</button></p>"


This can come back in 1 record to 100s of records.
I use this JSON to perform multiple tasks using one data pull.

What I need tho, is as one of the tasks to pull a subset out of this set into it's own JSON.

I need Lat, Lng, and Data beside itself.
Yes, it's for a google map.

How would I grep the JSON to create a new json with just the three columns?
I don't want to change the data pull, because Tasks 2-4 have need of the rest of the columns and I only want to do one data pull.

Thanks much.
Question by:Evan Cutler
    LVL 25

    Accepted Solution

    You could just assign the data to a new variable in a loop, e.g.
        var subsetJSON = new Array;
        for ( i=0; i<Markerdata.length; i++ ) {
            subsetJSON[i] = { "Lat"  : Markerdata[i].Lat
                             ,"Lng"  : Markerdata[i].Lng
                             ,"data" : Markerdata[i].data

    Open in new window

    LVL 9

    Author Closing Comment

    by:Evan Cutler
    You know,
    it's always the easy stuff that gets you.

    That is an awesome answer.
    My dumb luck, the code I would have made would be 85 lines long.

    Thanks much.
    LVL 25

    Expert Comment

    >> You know, it's always the easy stuff that gets you.
    Yup ... totally agree!  When your head down working hard on a solution it is way too easy to over-think every problem ... sometimes you need to stop, talk a walk and come back with a clear mind.
    Thanks for the points and best of luck with the rest of your code.
    LVL 9

    Author Comment

    by:Evan Cutler
    Yeah,  That's when I stop and "offer points"

    Thanks much

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Course: HTML5 Specialist

    HTML5 development skills are critical to all developers. HTML5 is the foundation to almost any development process. That's why business, design studios, development shops and other organizations need HTML5 developers. Get your foot in the door as a HTML5 specialist.

    DOM Attributes and Properties treatment with jQuery 1.6 by Ivo Stoykov jQuery ( 1.6 introduces .prop() ( and .removeProp() ( methods which allow modifying or removi…
    Introduction Got endorsements from your clients?  Great!  There is almost nothing better than word-of-mouth advertising.  But how can you do that on the internet?  Sure you can make a page for endorsement quotations and list them all, but who is …
    The viewer will learn how to dynamically set the form action using jQuery.
    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)

    737 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

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now