Skip to content

message.setAllJSONObjects

Signature: message.setAllJSONObjects(nodePath, value)

Returns: void

Find all nodes that match nodePath and set each nodes value.

Note

The value is of type 'Object' and not 'String' making this call type-aware.

Note

This method only applies to JSON-formatted messages.

Parameters

Type Name Description Default
String nodePath the node path (XPath, HPath, Column ID, etc.)
Object value the new value for each matching node

Example

// Given a JSON message like:
message = qie.createJSONMessage(
   JSON.stringify(
      {
         "people": [
            { "name": "Pablo",   "prefs": {"loves":["cats"]} },
            { "name": "Fernando","prefs": {"loves":["dogs"]} },
            { "name": "Sophie",  "prefs": {"loves":["cats"]} },
            { "name": "Jenni",   "prefs": {"loves":["dogs"]} }
         ]
      }
   )
);

// Replace JSON object with another JSON object
message.setAllJSONObjects(
   "/people/[contains(/prefs/loves/[],'cats')]/prefs",
   {"loves":["cats","flowers"]}
);

message.setAllJSONObjects(
   "/people/[contains(/prefs/loves/[],'dogs')]/prefs",
   {"loves":["dogs","walks on the beach"]}
);

// Resulting JSON:
// {
//     "people": [
//        { "name": "Pablo", "prefs": { "loves": ["cats","flowers"]} },
//        { "name": "Fernando", "prefs": { "loves": ["dogs", "walks on the beach"]} },
//        { "name": "Sophie", "prefs": { "loves": ["cats","flowers"]} },
//        { "name": "Jenni", "prefs": { "loves": ["dogs","walks on the beach"]} }
//     ]
// }