AnsweredAssumed Answered

JSONSetElement and nested Arrays

Question asked by fmdataweb on May 10, 2018
Latest reply on May 10, 2018 by user19752

I'm trying to create the following JSON in a looping script:



"attributes": [{

"id": 1,

"name": "color",

"options": [






"id": 2,

"name": "size",

"options": [








I need to create an array of "attributes" which also include a nested array of "options". In my looping script I first create the attributes, e.g.:


$attributes = [{"id":1,"name":"color","position":1}]


and then in an inner loop I create the options, e.g.:


$options = ["Blue","Red"]


but I can't come up with the correct syntax to add the $options array to the $attributes array, e.g.:


JSONSetElement ( $attributes ; "options" ; $options; JSONArray )


I know I need to target each attribute using the attributes[0] syntax and I have counter variables to use here for this purpose but I just can't get the correct syntax working here.