API Returns too much data - Need to extract

I have a GPS API that returns this

{“Response”:{“MetaInfo”:{“Timestamp”:“2021-08-16T11:42:04.830+0000”},“View”:[{"_type":“SearchResultsViewType”,“ViewId”:0,“Result”:[{“Relevance”:0.91,“MatchLevel”:“houseNumber”,“MatchQuality”:{“Country”:1.0,“City”:1.0,“Street”:[0.85],“HouseNumber”:1.0},“MatchType”:“pointAddress”,“Location”:{“LocationId”:“NT_qxGXgb3G3cd.7rBUiG7R6C_3A”,“LocationType”:“point”,“DisplayPosition”:{“Latitude”:-34.03144,“Longitude”:24.91555},“NavigationPosition”:[{“Latitude”:-34.03162,“Longitude”:24.91537}],“MapView”:{“TopLeft”:{“Latitude”:-34.0303158,“Longitude”:24.9141935},“BottomRight”:{“Latitude”:-34.0325642,“Longitude”:24.9169065}},“Address”:{“Label”:“7 Blombos St, Jeffreys Bay, 6330, South Africa”,“Country”:“ZAF”,“State”:“Eastern Cape”,“County”:“Kouga”,“City”:“Jeffreys Bay”,“District”:“Noorskloofpunt”,“Street”:“Blombos St”,“HouseNumber”:“7”,“PostalCode”:“6330”,“AdditionalData”:[{“value”:“South Africa”,“key”:“CountryName”},{“value”:“Eastern Cape”,“key”:“StateName”},{“value”:“Kouga”,“key”:“CountyName”}]}}}]}]}}

but I need to only extract this…

"NavigationPosition":[{“Latitude”:-34.03162,“Longitude”:24.91537}]

Can anyone tell me how to isolate this data from the returned json

Thanks

Tony

blocks - 2021-08-16T141634.696

You should search​:mag: on community before posting.

Here is a whole guide on JSON data.

1 Like

Yes, but that’s not the problem

The problem is that that data I NEED seems to be be NESTED inside other data

The question is how to extract just the Long and Lat

As you can see in the block, the first Notify shows me ALL THE JSON

Its the second that is not returning just the data I need

Thanks

Your data is in

Response
    View
        Result
            Location

Thanks

I get the

does that mean I need to drill down to the data I want and if so, then I dont understand your method.

I, so close. Please help

thanks

When you say COUPLE, havent I already done that?

Use this extension to turn JSON into a dictionary. After converting, you can just play with the dictionary.

Do not need Any Extension.
Use Dictionary or Lookup pairs Key Block

This is the ERROR I get

Argument #1 (not found) to ‘com.google.appinventor.components.runtime.util.YailDictionary.walkKeyPath(com.google.appinventor.components.runtime.util.YailObject,java.util.List)’ has wrong type (java.lang.String) (java.lang.String cannot be cast to com.google.appinventor.components.runtime.util.YailObject)

See the structure of your json in order to understand how to get values

yes, I see that but when I go to “Location” I get the error below

Argument #1 (not found) to ‘com.google.appinventor.components.runtime.util.YailDictionary.walkKeyPath(com.google.appinventor.components.runtime.util.YailObject,java.util.List)’ has wrong type (java.lang.String) (java.lang.String cannot be cast to com.google.appinventor.components.runtime.util.YailObject)

BTW, I finally got Companion to work. :slight_smile:

Im getting this

Expected a number for an index, but got “Location” instead. WTH

I really enjoy being “helped” half way…

Please can someone tell me what I m doing wrong.

Thanks

can you show us, what have you tried so for this to get value?

Tghis is as far as I get

Im getting the data in but I still cannot isolate what I need

this

Anyone, Please

convert web rsponse to json text, count the no of list. try to catch in which list item the location list is present. then use the select list item block to get the data…

Thanks, which block do I use to do that?

i tried like this and got succeed…

Yes, your method might work for a very simply JSON but mine is NESTED TO HELL

{“Response”:{“MetaInfo”:{“Timestamp”:“2021-08-16T11:42:04.830+0000”},“View”:[{"_type":“SearchResultsViewType”,“ViewId”:0,“Result”:[{“Relevance”:0.91,“MatchLevel”:“houseNumber”,“MatchQuality”:{“Country”:1.0,“City”:1.0,“Street”:[0.85],“HouseNumber”:1.0},“MatchType”:“pointAddress”,“Location”:{“LocationId”:“NT_qxGXgb3G3cd.7rBUiG7R6C_3A”,“LocationType”:“point”,“DisplayPosition”:{“Latitude”:-34.03144,“Longitude”:24.91555}, “NavigationPosition”:[{“Latitude”:-34.03162,“Longitude”:24.91537}] ,“MapView”:{“TopLeft”:{“Latitude”:-34.0303158,“Longitude”:24.9141935},“BottomRight”:{“Latitude”:-34.0325642,“Longitude”:24.9169065}},“Address”:{“Label”:“7 Blombos St, Jeffreys Bay, 6330, South Africa”,“Country”:“ZAF”,“State”:“Eastern Cape”,“County”:“Kouga”,“City”:“Jeffreys Bay”,“District”:“Noorskloofpunt”,“Street”:“Blombos St”,“HouseNumber”:“7”,“PostalCode”:“6330”,“AdditionalData”:[{“value”:“South Africa”,“key”:“CountryName”},{“value”:“Eastern Cape”,“key”:“StateName”},{“value”:“Kouga”,“key”:“CountyName”}]}}}]}]}}

BUT I must say I cannot belive that no one wants to help especially when for a real “programmer” Im sure my error is a clear as daylight