message.addJSONNumberBefore¶
Signature: message.addJSONNumberBefore(nodePath, childNode, value)
Returns: void
Add the specified childNode to the first node that matches nodePath.
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 | |
| String or Number | value | the value of the child node to add |
Example¶
// Examples of how to use addJSONNumberBefore
// Given a JSON message like:
message = qie.createJSONMessage(
JSON.stringify(
{
"name": "Jared",
"height": "215cm"
}
)
);
// Example: value as Number (JS number - note behavior)
message.addJSONNumberBefore(
"/name", // nodePath - insert BEFORE this node
"age", // childNode - name of the new node
41 // value (JS Number → may result in decimal)
);
// Example: value as String (will be converted to Number)
message.addJSONNumberBefore(
"/age", // nodePath
"yearsAtJob",
"10" // value (String → Number)
);
// Example: value as Number (Java Integer)
message.addJSONNumberBefore(
"/yearsAtJob",
"numberOfKids",
new java.lang.Integer(3) // value (Number)
);
// Resulting JSON:
// {
// "numberOfKids": 3,
// "yearsAtJob": 10,
// "age": 41.0,
// "name": "Jared",
// "height": "215cm"
// }