Change node: add / Delete property in json

Hello,

i have a json like this:

[
  {
    "externalDeviceId": "b827ebe81d30.2",
    "deviceCookie": {
      "updatedcookie": "old or new value"
    },
    "friendlyName": "Z2 Perron\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000",
    "manufacturerInfo": {
      "manufacturerName": "TEXECOM",
      "modelName": "Texecom detector",
      "hwVersion": "N/A",
      "swVersion": "N/A"
    },
    "deviceContext": {
      "roomName": "Texecom panel",
      "groups": [
        "Salon Motions",
        "House Motions"
      ],
      "categories": [
        "motion-sensor"
      ]
    },
    "deviceHandlerType": "7505e0c4-416f-4afa-ad3e-8c4cc6c3be9d",
    "deviceUniqueId": "b827ebe81d30.2"
  },
  {
    "externalDeviceId": "b827ebe81d30.3",
    "deviceCookie": {
      "updatedcookie": "old or new value"
    },
    "friendlyName": "Z3 PIR Salon Wire\u0000\u0000",
    "manufacturerInfo": {
      "manufacturerName": "TEXECOM",
      "modelName": "Texecom detector",
      "hwVersion": "N/A",
      "swVersion": "N/A"
    },
    "deviceContext": {
      "roomName": "Texecom panel",
      "groups": [
        "Salon Motions",
        "House Motions"
      ],
      "categories": [
        "motion-sensor"
      ]
    },
    "deviceHandlerType": "7505e0c4-416f-4afa-ad3e-8c4cc6c3be9d",
    "deviceUniqueId": "b827ebe81d30.3"
  },
  {
    "externalDeviceId": "b827ebe81d30.4",
    "deviceCookie": {
      "updatedcookie": "old or new value"
    },
    "friendlyName": "Z4 Terrasse\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000",
    "manufacturerInfo": {
      "manufacturerName": "TEXECOM",
      "modelName": "Texecom detector",
      "hwVersion": "N/A",
      "swVersion": "N/A"
    },
    "deviceContext": {
      "roomName": "Texecom panel",
      "groups": [
        "Salon Motions",
        "House Motions"
      ],
      "categories": [
        "motion-sensor"
      ]
    },
    "deviceHandlerType": "7505e0c4-416f-4afa-ad3e-8c4cc6c3be9d",
    "deviceUniqueId": "b827ebe81d30.4"
  }
]

I would delete all *.deviceContext.groups in a change node, is it possible?
and i would like add aproperty "enable" for each object in the array,

may you explain me how to do it?.

Did you try just using the delete option with msg.deviceContext.groups?

To delete groups from all objects in the array and add enable
e.g.

[{"id":"8f75de0e.8dfd88","type":"inject","z":"8d22ae29.7df6d","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[{\"externalDeviceId\":\"b827ebe81d30.2\",\"deviceCookie\":{\"updatedcookie\":\"old or new value\"},\"friendlyName\":\"Z2 Perron\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\",\"manufacturerInfo\":{\"manufacturerName\":\"TEXECOM\",\"modelName\":\"Texecom detector\",\"hwVersion\":\"N/A\",\"swVersion\":\"N/A\"},\"deviceContext\":{\"roomName\":\"Texecom panel\",\"groups\":[\"Salon Motions\",\"House Motions\"],\"categories\":[\"motion-sensor\"]},\"deviceHandlerType\":\"7505e0c4-416f-4afa-ad3e-8c4cc6c3be9d\",\"deviceUniqueId\":\"b827ebe81d30.2\"},{\"externalDeviceId\":\"b827ebe81d30.3\",\"deviceCookie\":{\"updatedcookie\":\"old or new value\"},\"friendlyName\":\"Z3 PIR Salon Wire\\u0000\\u0000\",\"manufacturerInfo\":{\"manufacturerName\":\"TEXECOM\",\"modelName\":\"Texecom detector\",\"hwVersion\":\"N/A\",\"swVersion\":\"N/A\"},\"deviceContext\":{\"roomName\":\"Texecom panel\",\"groups\":[\"Salon Motions\",\"House Motions\"],\"categories\":[\"motion-sensor\"]},\"deviceHandlerType\":\"7505e0c4-416f-4afa-ad3e-8c4cc6c3be9d\",\"deviceUniqueId\":\"b827ebe81d30.3\"},{\"externalDeviceId\":\"b827ebe81d30.4\",\"deviceCookie\":{\"updatedcookie\":\"old or new value\"},\"friendlyName\":\"Z4 Terrasse\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\",\"manufacturerInfo\":{\"manufacturerName\":\"TEXECOM\",\"modelName\":\"Texecom detector\",\"hwVersion\":\"N/A\",\"swVersion\":\"N/A\"},\"deviceContext\":{\"roomName\":\"Texecom panel\",\"groups\":[\"Salon Motions\",\"House Motions\"],\"categories\":[\"motion-sensor\"]},\"deviceHandlerType\":\"7505e0c4-416f-4afa-ad3e-8c4cc6c3be9d\",\"deviceUniqueId\":\"b827ebe81d30.4\"}]","payloadType":"json","x":170,"y":1920,"wires":[["8e83525e.d9dfd"]]},{"id":"8e83525e.d9dfd","type":"change","z":"8d22ae29.7df6d","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload ~> |[*].deviceContext|deviceContext,['groups']|\t","tot":"jsonata"},{"t":"set","p":"payload","pt":"msg","to":"payload ~> |[*]|$merge([$,{\"enable\":true}])|\t","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":330,"y":1920,"wires":[["54f03fee.1ad538"]]},{"id":"54f03fee.1ad538","type":"debug","z":"8d22ae29.7df6d","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":530,"y":1920,"wires":[]}]

It's perfect!

:smiling_face_with_three_hearts:

Thanks!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.