Skip to content

message.addNumberToJSON

Signature: message.addNumberToJSON(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 addNumberToJSON
// Given a JSON message like:
message = qie.createJSONMessage(
   JSON.stringify(
      {
         "name": "David",
         "occupation": "plumber"
      }
   )
);


// Example: value as String (will be converted to Number)
message.addNumberToJSON(
   "/",        // nodePath - root node
   "age",      // childNode - name of the new node
   "28"        // value (String → Number)
);


// Example: value as Number (Java Integer)
message.addNumberToJSON(
   "/",                         // nodePath
   "yearsExperience",           // childNode
   new java.lang.Integer(5)     // value (Number)
);


// Example: value as Number (JS number - note behavior)
message.addNumberToJSON(
   "/",        // nodePath
   "rating",   // childNode
   4.5         // value (JS Number → may result in decimal)
);

// Resulting JSON:
// {
//     "name": "David",
//     "occupation": "plumber",
//     "age": 28,
//     "yearsExperience": 5,
//     "rating": 4.5
// }