Skip to content

message.addJSONObjectBefore

Signature: message.addJSONObjectBefore(nodePath, childNode, value)

Returns: void

Add the specified childNode to the first node that matches nodePath.

Note

The value is of type 'Object' and not 'String' making this call type-aware.

Note

This method only applies to JSON-formatted messages.

Parameters

Type Name Description Default
String nodePath the node path (XPath, HPath, Column ID, etc.)
String childNode the name of the child node to add
Object value the value of the child node to add

Example

// Given a JSON message like:
message = qie.createJSONMessage(
    JSON.stringify(
        {
            "name": "David",
            "age": 44
        }
    )
);

// Add an object-valued child node immediately BEFORE the node at nodePath
message.addJSONObjectBefore(
    "/name",                        // nodePath to insert before
    "children",                     // name of the child node
    `[
        { "name": "Kacie" },
        { "name": "Jaime" }
    ]`                              // value of the child node
);

// Resulting JSON:
// {
//   "children": [
//       { "name": "Kacie" },
//       { "name": "Jaime" }
//   ],
//   "name": "David",
//   "age": 44
// }