Extract json data from API service

I’m making a call to an API service, I get the result as JSON. I want to extract just one or two key/value from the result. How could I possibly do this in the business logic or event handler?

I see the JSON data type in the Data schema but but I don’t want to save the whole object since I only need 1 or 2 values from it.

Hello @Peter_J

We will be happy to assist you. I need to ask you a few more questions so I can understand the problem better.
Do you want to save the resulting JSON into a JSON type column?

Thanks @Volodymyr_Ialovyi

Here for example:

{
                        "dragPoint": false,
                        "displayLatLng": {
                            "lng": -122.011923,
                            "lat": 37.331272
                        },
                        "adminArea4": "Santa Clara County",
                        "unknownInput": "",
                        "adminArea5": "Cupertino",
                        "adminArea6": "",
                        "postalCode": "95914",
                        "adminArea1": "US",
                        "adminArea3": "CA",
                        "type": "s",
                        "sideOfStreet": "N",
                        "adminArea6Type": "Neighborhood",
                        "geocodeQualityCode": "B1AAX",
                        "adminArea4Type": "County",
                        "linkId": "0",
                        "street": "Apple Park Way",
                        "mapUrl": "http://open.mapquestapi.com/staticmap/v5/map?key=caybGfnczGihgpUtSWMhqx3ei9JCqk80&type=map&size=225,160&locations=37.3312719,-122.0119227|marker-sm-50318A-3&scalebar=true&zoom=15&rand=1352159435",
                        "adminArea5Type": "City",
                        "geocodeQuality": "STREET",
                        "adminArea1Type": "Country",
                        "latLng": {
                            "lng": -122.011923,
                            "lat": 37.331272
                        },
                        "adminArea3Type": "State" 
}

Let’s say here I only need the values for lng & lat from the displayLatLng.
So ideally from this response, I would like to save the values lng = -122.011923 and lat = 37.331272 in the database

Hello @Peter_J

Try something like this:

Doesn’t seem to work

Could you please show how you’re saving the data?

Yea for sure.

And here’s a query:

[
	{
		"city": null,
		"created": 1601549007000,
		"InputAddress": "One Apple Park Way Cupertino, CA 95014",
		"___class": "Address",
		"ownerId": null,
		"updated": null,
		"objectId": "EDE5BA8A-74AD-4650-A3AE-EDA1EA8508B8",
		"GeoCode": {
			"info": {
				"messages": [],
				"copyright": {
					"text": "© 2020 MapQuest, Inc.",
					"imageUrl": "http://api.mqcdn.com/res/mqlogo.gif",
					"imageAltText": "© 2020 MapQuest, Inc."
				},
				"statuscode": 0
			},
			"options": {
				"thumbMaps": true,
				"maxResults": -1,
				"ignoreLatLngInput": false
			},
			"results": [
				{
					"locations": [
						{
							"type": "s",
							"latLng": {
								"lat": 39.78373,
								"lng": -100.445882
							},
							"linkId": "0",
							"mapUrl": "http://open.mapquestapi.com/staticmap/v5/map?key=caybGfnczGihgpUtSWMhqx3ei9JCqk80&type=map&size=225,160&locations=39.7837304,-100.4458825|marker-sm-50318A-1&scalebar=true&zoom=2&rand=1000365711",
							"street": "",
							"dragPoint": false,
							"adminArea1": "US",
							"adminArea3": "",
							"adminArea4": "",
							"adminArea5": "",
							"adminArea6": "",
							"postalCode": "",
							"sideOfStreet": "N",
							"unknownInput": "",
							"displayLatLng": {
								"lat": 39.78373,
								"lng": -100.445882
							},
							"adminArea1Type": "Country",
							"adminArea3Type": "State",
							"adminArea4Type": "County",
							"adminArea5Type": "City",
							"adminArea6Type": "Neighborhood",
							"geocodeQuality": "COUNTRY",
							"geocodeQualityCode": "A1XXX"
						}
					],
					"providedLocation": {
						"location": "One Apple Park Way Cupertino, CA 95014"
					}
				}
			]
		}
	}
]

Do you use codeless to store data? if so, what does the codeless logic you use do? When you wrote doesn't seem to work, I assume you referred to the logic in place that saves the data. I’d like to see that if possible.

Oh my bad. I want to retrieve the lat and lng from the json record in the GeoCode column.

Retrieving the column works fine:

But I can’t figure out how to retrieve just the lat and lng key/values from it.

both results and locations are arrays. Do you need to retrieve displayLatLng from a particular element of those arrays? The reason it doesn’t work is because the JSON Path doesn’t reference the array element.

Yes exactly, from the first element.
I also tried GeoCode->$.results[0].locations[0].displayLatLng

ok, it is super clear now. Could you please let me know your application ID so I can give it a try?

Yes of course. Here 2ED7F377-22E4-00FB-FF25-BFB87366B600

Hi @Peter_J,

The problem is with the syntax of the JSON Path. The actual JSON Path must be included into single quotes:

GeoCode->'$.results[0].locations[0].displayLatLng'

I also modified the Codeless logic in your GetAddress service and it now returns the data.

Regards,
Mark

1 Like

Awesome, thanks @mark-piller