how to add more elements to json arrayusing curl put method

Not applicable

this is the json file I have now: { "name": "property", "subproperty": [ { "subpropertyname": "subproperty2", "price": 100 }, { "subpropertyname": "subproperty3", "price": 300 } ] } here I want to add one more sub property.how can I do that using curl put method?

Solved Solved
0 5 612
1 ACCEPTED SOLUTION

Hi @Tijo Thomas

In an Apigee API BaaS PUT, you can't add an element to the array. By referencing "subproperty" in your PUT payload, you will replace the entire subproperty with whatever you mention.

API BaaS is a graph database. You could make each subproperty a separate element in a subproperty collection, and then add subproperties one-by-one to your base element by adding connections. This is how you would do this using BaaS.

In any other context, how an element is modified is a function of the design of the API -- there is no specific "cURL" way of adding an element to an embedded array.

View solution in original post

5 REPLIES 5

You might have to elaborate a bit more on your intent.

Not applicable

@Vikaas Sir,can we add one more element in the array with out over writing the existing array.Now we have 2 elements in the array after adding array will be having 3 elements including the already existing 2 elements.

Hi @Tijo Thomas

In an Apigee API BaaS PUT, you can't add an element to the array. By referencing "subproperty" in your PUT payload, you will replace the entire subproperty with whatever you mention.

API BaaS is a graph database. You could make each subproperty a separate element in a subproperty collection, and then add subproperties one-by-one to your base element by adding connections. This is how you would do this using BaaS.

In any other context, how an element is modified is a function of the design of the API -- there is no specific "cURL" way of adding an element to an embedded array.

But @Tijo Thomas - keep in mind that you could accomplish what you want by using multiple distinct steps: retrieve the entity, and then add the element to the array, and then PUT the modified entity back.

Also remember @Dino and @Tijo Thomas that there is a potential race condition here if multiple people/processes update that entity. If you GET the entity, then PUT the updated one back, you'd overwrite any changes that happened to the entity after you did the GET. Just something to keep in mind.