Question

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

  • 16 August 2020
  • 2 replies
  • 383 views

Userlevel 1

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


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

Userlevel 7
Badge +9

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)

 

Userlevel 7
Badge +10

Hi @Commissionly 

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