Skip to main content
Question

How do I parse JSON in an intergration api step to create key value pairs


I am building an intergration (not ZAP) with Monday.com by pulling data via their api.

The exampl api JSON payload is below. 

I need to change column_values Key/value pairs so that the first value is the Key and sendond value is the Value

ie

"column_values": [ { "id": "status", "text": "Working on it" } ]

I need the result to be

"column_values"[{"status": "Working on it"}]

 

I am looking for the code I need to but between

const results = response.json;

and

return results;

 

in the code mode on the API Intergration step.

 

the full api payload example is 

{
  "data": {
    "boards": [
      {
        "name": "Test Board",
        "items": [
          {
            "name": "Name Change",
            "id": "625495642",
            "column_values": [
              {
                "id": "person",
                "text": ""
              },
              {
                "id": "subitems",
                "text": "Subitem 1, Subitem 2"
              },
              {
                "id": "status",
                "text": "Working on it"
              },
              {
                "id": "dropdown",
                "text": "Test1"
              },
              {
                "id": "formula",
                "text": ""
              }
            ]
          }
        ]
      }
    ]
  },
  "account_id": 1111
}

Thanks in advance

Did this topic help you find an answer to your question?
This post has been closed for comments. Please create a new post if you need help or have a question about this topic.

2 replies

andywingrave
Forum|alt.badge.img+9
  • Zapier Expert
  • 854 replies
  • August 19, 2020

Something like this is what I think you need:

 

	let objName = combined.map((a) => a.columnName);
	let objValue = combined.map((a) => a.columnValue);

	function mapToObject(keys, values) {
		return keys.reduce(
			(sum, key, index) => Object.assign(sum, { [key]: values[index] }),
			{}
		);
	}
	return mapToObject(objName, objValue)

 


AndrewJDavison_Luhhu
Forum|alt.badge.img+10

Hi @Commissionly 

Just checking in. Were you able to get this sorted?