Skip to content

message.setJSONString

Signature: message.setJSONString(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.

Note

Calling message.setJSONString(nodePath, value) without the instance parameter sets the first node instance that matches nodePath.

Note

This function is the same as calling message.setNode().

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 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

// Example: Set JSON nodes to string values, including creating a missing node (forceNode=true).

// Sample JSON message structure
message = qie.createJSONMessage(JSON.stringify(
{
    userProfile: {
        name: "John Smith",
        preferences: {
            theme: "dark",
            language: "en"
        }
    },
    status: "active"
}));

// Update existing string nodes
var nameBefore = message.getNode("/userProfile/name"); // "John Smith"
message.setJSONString("/userProfile/name", "Jane Doe");
var nameAfter = message.getNode("/userProfile/name");  // "Jane Doe"

var languageBefore = message.getNode("/userProfile/preferences/language"); // "en"
message.setJSONString("/userProfile/preferences/language", "fr");
var languageAfter = message.getNode("/userProfile/preferences/language");  // "fr"

// Create missing node and set it to a string
message.setJSONString(
"/userProfile/preferences/country", // node path
"US",                               // value
1,                                  // instance
true                                // create node if it doesn't exist
);
var country = message.getNode("/userProfile/preferences/country"); // "US"