cJSON icon indicating copy to clipboard operation
cJSON copied to clipboard

Feature: array of objects

Open kmilo17pet opened this issue 3 years ago • 1 comments

After searching the library for a while, I did not find an API to be able to create an array of objects to obtain something like I show below

{
	"property" : "value",
	"array": [
		{
			"object1":	{
				"prop_obj1":	value,
				"prop_obj2":	value,
				"prop_obj3":	value
			}
		},
		{
			"object2":	{
				"prop_obj1":	value,
				"prop_obj2":	value,
				"prop_obj3":	value
			}
		},
		{
			"object3":	{
				"prop_obj1":	value,
				"prop_obj2":	value,
				"prop_obj3":	value
			}
		}
	]
}

kmilo17pet avatar Jun 23 '21 14:06 kmilo17pet

You probably can by using different functions, check out this example code. There's one using helper functions and one not. The way I see you could do this is the following.

  • generate an empty json object
  • add object to base empty json_object and add name 'property' with value.
  • array cJSON data structure. add empty array to json_object
  • for each object (object1,2,3..), add an empty object array to array with the object name, then another array inside it with the properties you list

TrevCan avatar Oct 31 '21 19:10 TrevCan