parse JSON from Ajax pull in JQUERY

Greetings,

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

 $.ajax({
                 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",
"Name" :      "ADENA REGIONAL MEDICAL CENTER",
"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.
LVL 9
Evan CutlerVolunteer Chief Information OfficerAsked:
Who is Participating?
 
lwadwellConnect With a Mentor Commented:
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

0
 
Evan CutlerVolunteer Chief Information OfficerAuthor Commented:
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.
0
 
lwadwellCommented:
>> 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.
0
 
Evan CutlerVolunteer Chief Information OfficerAuthor Commented:
Yeah,  That's when I stop and "offer points"  sometimes...lol

Thanks much
0
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.

All Courses

From novice to tech pro — start learning today.