message.setJSONNull¶
Signature: message.setJSONNull(nodePath, 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 null.
Note
Calling message.setJSONNull(nodePath) 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.) | |
| 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¶
// Example: Set existing JSON nodes to null, and create a missing node (forceNode=true) then set it to null.
// Sample JSON message structure
message = qie.createJSONMessage(JSON.stringify(
{
userProfile: {
name: "John Doe",
email: "john@example.com",
preferences: {
theme: "dark",
notificationsEnabled: true
}
},
sessionStatus: "active"
}));
// Set existing nodes to null
var notificationsBefore = message.getNode("/userProfile/preferences/notificationsEnabled"); // true
message.setJSONNull("/userProfile/preferences/notificationsEnabled");
var notificationsAfter = message.getNode("/userProfile/preferences/notificationsEnabled"); // null
var sessionStatusBefore = message.getNode("/sessionStatus"); // "active"
message.setJSONNull("/sessionStatus");
var sessionStatusAfter = message.getNode("/sessionStatus"); // null
// Create missing node and set it to null
message.setJSONNull(
"/userProfile/profilePicture", // node path
1, // instance
true // create node if it doesn't exist
);
var profilePicture = message.getNode("/userProfile/profilePicture"); // null