message.setJSONNumber¶
Signature: message.setJSONNumber(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 it to value.
Note
A JavaScript number literal such as 1 is passed to QIE as a floating-point value, so a whole number can serialize with a trailing decimal (for example, 1.0). Use message.setJSONInteger() when the target field must be a JSON integer.
Note
Calling message.setJSONNumber(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 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 setJSONNumber
// Sample JSON message structure
message = qie.createJSONMessage(JSON.stringify(
{
userProfile: {
name: "Jane Doe",
age: 30,
preferences: {
theme: "light"
}
},
accountStatus: "active"
}));
// Example: value as Number (JS number - default behavior, first instance)
message.setJSONNumber(
"/userProfile/age", // nodePath - target node
31 // value (Number)
);
// Example: value as String (will be converted to Number)
message.setJSONNumber(
"/userProfile/age",
"32" // value (String → Number)
);
// Example: value as a JS number literal (serialized as a double)
message.setJSONNumber(
"/userProfile/age",
33 // value (Number) → serialized as 33.0 because a JS number literal is passed as a double
);
// Example: specify instance (1-based index)
message.setJSONNumber(
"/userProfile/age", // nodePath
34, // value (JS Number → may result in decimal)
1 // instance (first match)
);
// Example: create missing node (forceNode = true)
message.setJSONNumber(
"/userProfile/preferences/alertsEnabled", // nodePath (does not exist yet)
"1", // value (String → Number)
1, // instance
true // forceNode - create if missing
);
// Resulting JSON (after operations):
// {
// "userProfile": {
// "name": "Jane Doe",
// "age": 34.0,
// "preferences": {
// "theme": "light",
// "alertsEnabled": 1
// }
// },
// "accountStatus": "active"
// }