Sample code for 30+ languages & platforms
Xojo Plugin

Insert JSON Object into another JSON Object

See more JSON Examples

Demonstrates how to insert one JSON object into another. Effectively, the JSON object must be copied into the other..

Chilkat Xojo Plugin Downloads

Xojo Plugin
// Imagine we have two separate JSON objects.
Dim jsonA As New Chilkat.JsonObject
Dim success As Boolean
success = jsonA.UpdateString("animal","zebra")
success = jsonA.UpdateString("colors[0]","white")
success = jsonA.UpdateString("colors[1]","black")

jsonA.EmitCompact = False
System.DebugLog(jsonA.Emit())

// jsonA contains:

// {
//   "animal": "zebra",
//   "colors": [
//     "white",
//     "black"
//   ]
// }

Dim jsonB As New Chilkat.JsonObject
success = jsonB.UpdateString("type","mammal")
success = jsonB.UpdateBool("carnivore",False)

jsonB.EmitCompact = False
System.DebugLog(jsonB.Emit())

// jsonB contains:

// {
//   "type": "mammal",
//   "carnivore": false
// }

// Let's say we want to insert jsonB into jsonA to get this:

// {
//   "animal": "zebra",
//   "info" " {
//       "type": "mammal",
//       "carnivore": false
// 	},
//   "colors": [
//     "white",
//     "black"
//   ]
// }

success = jsonA.AddObjectCopyAt(1,"info",jsonB)

System.DebugLog(jsonA.Emit())

// The result is this:

// {
//   "animal": "zebra",
//   "info": {
//     "type": "mammal",
//     "carnivore": false
//   },
//   "colors": [
//     "white",
//     "black"
//   ]
// }