Variable to Parts of JSON Request Body

The Google Places API (New) seems to allow looking up places for a single LatLon pair at a time. Here’s a valid request body:

{
  "includedTypes": ["spa"],
  "maxResultCount": 10,
  "locationRestriction": {
    "circle": {
      "center": {
        "latitude": 40.4436121,
        "longitude": -104.984106},
      "radius": 5000.0
    }
  }
}

I’m hoping to produce a workflow that loops over a list of latlons to concatenate the results at the end, but having trouble getting the JSON Request Body constructed correctly. Up to the “Column Combiner” node in the image below, I can get the following:

{   "includedTypes": ["spa"],   "maxResultCount": 10,   "locationRestriction":{
  "circle" : {
    "center" : {
      "latitude" : 40.4436121,
      "longitude" : -104.984106
    }
  }
}

If I add the radius = 500.0 key/value pair in the Columns to JSON node, the radius appears in the wrong place:

{
  "circle" : {
    "center" : {
      "latitude" : 40.4436121,
      "longitude" :-104.984106,
      "radius" : "500.0"
    }
  }
}

Appreciate any help!

Here is the draft workflow on Community Hub.

Hi!
I would advise against playing around with plain strings to compose JSON, as this can quickly introduce syntax errors. Please have a look at the workflow I attached. It creates the structure you need solely with Table to JSON nodes.
Kind regards,
Alexander

Looping Over LatLons Google Places (New) API.knwf (94.0 KB)

3 Likes

I was going to say, I just solved it a minute ago with a string approach, but was thinking there must be a non-string approach. Here is the string approach, but evaluating your workflow now to see if I can update it into a V2 :slight_smile:

Works wonderfully, thanks very much. Updated with looping part.

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.