Transform Object-Array to Key/Value

Hi,

I have to following input parameter in my module:

	{
		"name": "metadata",
		"spec": [
			{
				"name": "key",
				"type": "text",
				"label": "Key"
			},
			{
				"name": "value",
				"type": "text",
				"label": "Value"
			}
		],
		"type": "array",
		"label": "Metadata"
	}

I need to transform this into the following format for POST request:

{
      "key1": "value1",
      "key2": "value2"
}

How can I achieve this?

Best Regards
Jörg

@Jorg_Ackermann

Your example doesn’t make sense. None of the “to” values are in the “from”.

Hi Jim,
the first parat is the declaration of the input parameter for a custom app module. And the data collected there should be transferred into the form of the example.
Best Regards
Jörg

Hi @Jorg_Ackermann
I am not sure if I understand your requirement correctly, but I assume that you’re talking about json transformation according to a schema. Well, if that’s what you are looking for, then “Create JSON” module does just that. Obviously, you still need to map your object’s fields to the schema fields. Here is an example…

  1. Schema definition

  2. Field mappings and output

If you have such an input/output:

   "array":[
      {
         "name":"key1",
         "value":"value1"
      },
      {
         "name":"key2",
         "value":"value2"
      }
   

you can transform it to "key":"value" format by using the toCollection() function, for example transformation of module’s output could be:

"response": {
           "output": "{{toCollection(body, 'name', 'value')}}"
       }
}