Skip to content

message.setJSONInteger

Signature: message.setJSONInteger(nodePath, value, instance*, forceNode*)

Returns: void

Find the node instance that matches nodePath (or create the node if it doesn't exist and forceNode = true) and set its value as a whole number, serialized without a trailing decimal point (for example, 1, never 1.0).

Note

Use this instead of message.setJSONNumber() when the target field must be a JSON integer. A JavaScript number literal such as 1 is passed to QIE as a floating-point value, and setJSONNumber preserves that type, so it serializes as 1.0; setJSONInteger always emits 1.

Note

The value must be a whole number. A value with a fractional part (for example, 1.5) throws an error.

Note

Calling message.setJSONInteger(nodePath, value) without the instance parameter sets the first node instance 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 or Number value the new whole-number node value
Integer instance* (optional) the match instance to set. Use 1 for the first instance. 1
Boolean forceNode* (optional) create the node if it doesn't exist true

Example

// Examples of how to use setJSONInteger
// Sample JSON message structure
message = qie.createJSONMessage(JSON.stringify(
   {
      "task": {
         "name": "nightly-load"
      }
   }));


// Example: whole number serialized as an integer (1, not 1.0)
message.setJSONInteger(
   "/task/rowCount", // nodePath (created because forceNode = true)
   1,                // value (whole number)
   1,                // instance (first match)
   true              // forceNode - create if missing
);


// Example: value as String (created via the default forceNode = true)
message.setJSONInteger(
   "/task/exitCode",
   "0"              // value (String -> integer)
);

// Resulting JSON:
// {
//   "task": {
//     "name": "nightly-load",
//     "rowCount": 1,
//     "exitCode": 0
//   }
// }