Javascript function to parse complex json object

I am trying to parse a complex json object Here is the object.

I am using the following flow to parse the data

image

function getAllKeyValuePairs(obj, path = '') {
  const results = [];

  for (const key in obj) {
    if (obj.hasOwnProperty(key)) {
      const currentPath = path ? `${path}.${key}` : key;
      const value = obj[key];

      if (typeof value === 'object' && value !== null) {
        results.push(...getAllKeyValuePairs(value, currentPath));
      } else {
        results.push({ path: currentPath, value: value });
      }
    }
  }

  return results;
}

const myJsonObject = msg.payload

const allKeyValuePairs = getAllKeyValuePairs(myJsonObject);

allKeyValuePairs.forEach(item => {
console.log(`${item.path}: ${item.value}`);
});
[{"id":"6644ed21fe795c03","type":"function","z":"bec7048b1f74f182","name":"function 29","func":"function getAllKeyValuePairs(obj, path = '') {\n  const results = [];\n\n  for (const key in obj) {\n    if (obj.hasOwnProperty(key)) {\n      const currentPath = path ? `${path}.${key}` : key;\n      const value = obj[key];\n\n      if (typeof value === 'object' && value !== null) {\n        results.push(...getAllKeyValuePairs(value, currentPath));\n      } else {\n        results.push({ path: currentPath, value: value });\n      }\n    }\n  }\n\n  return results;\n}\n\nconst myJsonObject = msg.payload\n\nconst allKeyValuePairs = getAllKeyValuePairs(myJsonObject);\n\nallKeyValuePairs.forEach(item => {\nconsole.log(`${item.path}: ${item.value}`);\n});","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":430,"y":740,"wires":[["be6882c82fb414d3"]]},{"id":"be6882c82fb414d3","type":"debug","z":"bec7048b1f74f182","name":"debug 3","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":620,"y":740,"wires":[]},{"id":"d4ae6622b4e4681c","type":"template","z":"bec7048b1f74f182","name":"","field":"payload","fieldType":"msg","format":"json","syntax":"plain","template":"{\n    \"version\": \"5.21.22\",\n    \"system\": {\n        \"manufacturer\": \"Gigabyte Technology Co., Ltd.\",\n        \"model\": \"Z390 AORUS PRO WIFI\",\n        \"version\": \"Default string\",\n        \"serial\": \"Default string\",\n        \"uuid\": \"032e02b4-0499-058e-e506-470700080009\",\n        \"sku\": \"Default string\",\n        \"virtual\": false\n    },\n    \"bios\": {\n        \"vendor\": \"American Megatrends Inc.\",\n        \"version\": \"F10\",\n        \"releaseDate\": \"2019-06-04\",\n        \"revision\": \"\",\n        \"serial\": \"\"\n    },\n    \"baseboard\": {\n        \"manufacturer\": \"Gigabyte Technology Co., Ltd.\",\n        \"model\": \"Z390 AORUS PRO WIFI-CF\",\n        \"version\": \"x.x\",\n        \"serial\": \"\",\n        \"assetTag\": \"\",\n        \"memMax\": 68719476736,\n        \"memSlots\": 4\n    },\n    \"chassis\": {\n        \"manufacturer\": \"\",\n        \"model\": \"\",\n        \"type\": \"Desktop\",\n        \"version\": \"\",\n        \"serial\": \"\",\n        \"assetTag\": \"\",\n        \"sku\": \"\"\n    },\n    \"os\": {\n        \"platform\": \"Windows\",\n        \"distro\": \"Microsoft Windows 11 Pro\",\n        \"release\": \"10.0.26120\",\n        \"codename\": \"\",\n        \"kernel\": \"10.0.26120\",\n        \"arch\": \"x64\",\n        \"hostname\": \"w8be-prod\",\n        \"fqdn\": \"W8BE-PROD\",\n        \"codepage\": \"437\",\n        \"logofile\": \"windows\",\n        \"serial\": \"00330-80021-43272-AA568\",\n        \"build\": \"26120\",\n        \"servicepack\": \"0.0\",\n        \"uefi\": true,\n        \"hypervisor\": false,\n        \"remoteSession\": false\n    },\n    \"uuid\": {\n        \"os\": \"596d850e-1cbc-456d-81c8-9dbeb723a679\",\n        \"hardware\": \"032e02b4-0499-058e-e506-470700080009\",\n        \"macs\": [\n            \"b4:2e:99:8e:e5:47\"\n        ]\n    },\n    \"versions\": {\n        \"kernel\": \"10.0.26120\",\n        \"openssl\": \"3.0.13+quic\",\n        \"systemOpenssl\": \"\",\n        \"systemOpensslLib\": \"\",\n        \"node\": \"20.15.0\",\n        \"v8\": \"11.3.244.8-node.23\",\n        \"npm\": \"10.8.1\",\n        \"yarn\": \"\",\n        \"pm2\": \"\",\n        \"gulp\": \"\",\n        \"grunt\": \"\",\n        \"git\": \"2.47.0.windows.2\",\n        \"tsc\": \"\",\n        \"mysql\": \"\",\n        \"redis\": \"\",\n        \"mongodb\": \"\",\n        \"apache\": \"\",\n        \"nginx\": \"\",\n        \"php\": \"\",\n        \"docker\": \"\",\n        \"postfix\": \"\",\n        \"postgresql\": \"\",\n        \"perl\": \"\",\n        \"python\": \"3.11.0\",\n        \"python3\": \"\",\n        \"pip\": \"22.3\",\n        \"pip3\": \"22.3\",\n        \"java\": \"\",\n        \"gcc\": \"\",\n        \"virtualbox\": \"\",\n        \"bash\": \"\",\n        \"zsh\": \"\",\n        \"fish\": \"\",\n        \"powershell\": \"5.1.26100.2200:\",\n        \"dotnet\": \"4.8.09032\"\n    },\n    \"cpu\": {\n        \"manufacturer\": \"Intel\",\n        \"brand\": \"Core™ i9-9900K\",\n        \"vendor\": \"GenuineIntel\",\n        \"family\": \"6\",\n        \"model\": \"158\",\n        \"stepping\": \"13\",\n        \"revision\": \"\",\n        \"voltage\": \"\",\n        \"speed\": 3.6,\n        \"speedMin\": 3.6,\n        \"speedMax\": 3.6,\n        \"governor\": \"\",\n        \"cores\": 16,\n        \"physicalCores\": 8,\n        \"performanceCores\": 16,\n        \"efficiencyCores\": 0,\n        \"processors\": 1,\n        \"socket\": \"LGA1151\",\n        \"flags\": \"de pse tsc msr mce sep mtrr mca cmov psn clfsh ds acpi mmx fxsr sse sse2 ss htt tm ia64 pbe\",\n        \"virtualization\": false,\n        \"cache\": {\n            \"l1d\": 256,\n            \"l1i\": 256,\n            \"l2\": 2097152,\n            \"l3\": 16777216\n        }\n    },\n    \"graphics\": {\n        \"controllers\": [\n            {\n                \"vendor\": \"Advanced Micro Devices, Inc.\",\n                \"model\": \"ASUS Radeon RX 580 Series\",\n                \"bus\": \"PCI\",\n                \"vram\": 8192,\n                \"vramDynamic\": true,\n                \"subDeviceId\": \"2378148C\"\n            }\n        ],\n        \"displays\": [\n            {\n                \"vendor\": \"(Standard monitor types)\",\n                \"model\": \"Generic PnP Monitor\",\n                \"deviceName\": \"\\\\\\\\.\\\\DISPLAY2\",\n                \"main\": true,\n                \"builtin\": false,\n                \"connection\": \"DP\",\n                \"resolutionX\": 3072,\n                \"resolutionY\": 1728,\n                \"sizeX\": 53,\n                \"sizeY\": 30,\n                \"pixelDepth\": \"32\",\n                \"currentResX\": 3072,\n                \"currentResY\": 1728,\n                \"positionX\": 0,\n                \"positionY\": 0,\n                \"currentRefreshRate\": 60\n            },\n            {\n                \"vendor\": \"\",\n                \"model\": \"\",\n                \"deviceName\": \"\\\\\\\\.\\\\DISPLAY1\",\n                \"main\": false,\n                \"builtin\": false,\n                \"connection\": \"DP\",\n                \"resolutionX\": 1920,\n                \"resolutionY\": 1080,\n                \"sizeX\": 70,\n                \"sizeY\": 40,\n                \"pixelDepth\": \"32\",\n                \"currentResX\": 1920,\n                \"currentResY\": 1080,\n                \"positionX\": -1920,\n                \"positionY\": 0,\n                \"currentRefreshRate\": 60\n            },\n            {\n                \"vendor\": \"\",\n                \"model\": \"\",\n                \"deviceName\": \"\\\\\\\\.\\\\DISPLAY3\",\n                \"main\": false,\n                \"builtin\": false,\n                \"connection\": \"DP\",\n                \"resolutionX\": 2560,\n                \"resolutionY\": 1440,\n                \"sizeX\": 53,\n                \"sizeY\": 30,\n                \"pixelDepth\": \"32\",\n                \"currentResX\": 2560,\n                \"currentResY\": 1440,\n                \"positionX\": 3840,\n                \"positionY\": 0,\n                \"currentRefreshRate\": 60\n            }\n        ]\n    },\n    \"net\": [\n        {\n            \"iface\": \"Eth0\",\n            \"ifaceName\": \"Intel(R) Ethernet Connection (7) I219-V\",\n            \"default\": true,\n            \"ip4\": \"192.168.0.64\",\n            \"ip4subnet\": \"255.255.255.0\",\n            \"ip6\": \"2601:151:8300:e9c:9673:3210:7700:1c43\",\n            \"ip6subnet\": \"ffff:ffff:ffff:ffff::\",\n            \"mac\": \"b4:2e:99:8e:e5:47\",\n            \"internal\": false,\n            \"virtual\": false,\n            \"operstate\": \"up\",\n            \"type\": \"wired\",\n            \"duplex\": \"\",\n            \"mtu\": \"\",\n            \"speed\": 1000,\n            \"dhcp\": true,\n            \"dnsSuffix\": \"hsd1.wv.comcast.net\",\n            \"ieee8021xAuth\": \"Not defined\",\n            \"ieee8021xState\": \"Disabled\",\n            \"carrierChanges\": 0\n        },\n        {\n            \"iface\": \"Loopback Pseudo-Interface 1\",\n            \"ifaceName\": \"Loopback Pseudo-Interface 1\",\n            \"default\": false,\n            \"ip4\": \"127.0.0.1\",\n            \"ip4subnet\": \"255.0.0.0\",\n            \"ip6\": \"::1\",\n            \"ip6subnet\": \"ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff\",\n            \"mac\": \"00:00:00:00:00:00\",\n            \"internal\": true,\n            \"virtual\": false,\n            \"operstate\": \"down\",\n            \"type\": \"\",\n            \"duplex\": \"\",\n            \"mtu\": \"\",\n            \"speed\": null,\n            \"dhcp\": false,\n            \"dnsSuffix\": \"\",\n            \"ieee8021xAuth\": \"Not defined\",\n            \"ieee8021xState\": \"Disabled\",\n            \"carrierChanges\": 0\n        },\n        {\n            \"iface\": \"Wi-Fi\",\n            \"ifaceName\": \"Intel(R) Wireless-AC 9560 160MHz\",\n            \"default\": false,\n            \"ip4\": \"\",\n            \"ip4subnet\": \"\",\n            \"ip6\": \"\",\n            \"ip6subnet\": \"\",\n            \"mac\": \"\",\n            \"virtual\": false,\n            \"operstate\": \"down\",\n            \"type\": \"wireless\",\n            \"duplex\": \"\",\n            \"mtu\": \"\",\n            \"speed\": null,\n            \"dhcp\": true,\n            \"dnsSuffix\": \"\",\n            \"ieee8021xAuth\": \"Not defined\",\n            \"ieee8021xState\": \"Disabled\",\n            \"carrierChanges\": 0\n        }\n    ],\n    \"memLayout\": [\n        {\n            \"size\": 17179869184,\n            \"bank\": \"BANK 1\",\n            \"type\": \"DDR4\",\n            \"ecc\": false,\n            \"clockSpeed\": 3200,\n            \"formFactor\": \"DIMM\",\n            \"manufacturer\": \"04CD\",\n            \"partNum\": \"F4-3200C16-16GVK\",\n            \"serialNum\": \"00000000\",\n            \"voltageConfigured\": 1.2,\n            \"voltageMin\": 1.2,\n            \"voltageMax\": 1.2\n        },\n        {\n            \"size\": 17179869184,\n            \"bank\": \"BANK 3\",\n            \"type\": \"DDR4\",\n            \"ecc\": false,\n            \"clockSpeed\": 3200,\n            \"formFactor\": \"DIMM\",\n            \"manufacturer\": \"04CD\",\n            \"partNum\": \"F4-3200C16-16GVK\",\n            \"serialNum\": \"00000000\",\n            \"voltageConfigured\": 1.2,\n            \"voltageMin\": 1.2,\n            \"voltageMax\": 1.2\n        }\n    ],\n    \"diskLayout\": [\n        {\n            \"device\": \"\\\\\\\\.\\\\PHYSICALDRIVE4\",\n            \"type\": \"SSD\",\n            \"name\": \"SPCC M.2 PCIe SSD\",\n            \"vendor\": \"\",\n            \"size\": 256052966400,\n            \"bytesPerSector\": 512,\n            \"totalCylinders\": 31130,\n            \"totalHeads\": 255,\n            \"totalSectors\": 500103450,\n            \"totalTracks\": 7938150,\n            \"tracksPerCylinder\": 255,\n            \"sectorsPerTrack\": 63,\n            \"firmwareRevision\": \"S0614B0\",\n            \"serialNum\": \"0100_0000_0000_0000.\",\n            \"interfaceType\": \"NVMe\",\n            \"smartStatus\": \"Ok\",\n            \"temperature\": null\n        },\n        {\n            \"device\": \"\\\\\\\\.\\\\PHYSICALDRIVE1\",\n            \"type\": \"HD\",\n            \"name\": \"ST2000DM001-1CH164\",\n            \"vendor\": \"Seagate\",\n            \"size\": 2000396321280,\n            \"bytesPerSector\": 512,\n            \"totalCylinders\": 243201,\n            \"totalHeads\": 255,\n            \"totalSectors\": 3907024065,\n            \"totalTracks\": 62016255,\n            \"tracksPerCylinder\": 255,\n            \"sectorsPerTrack\": 63,\n            \"firmwareRevision\": \"HP36\",\n            \"serialNum\": \"Z1E8L0YY\",\n            \"interfaceType\": \"SATA\",\n            \"smartStatus\": \"Ok\",\n            \"temperature\": null\n        },\n        {\n            \"device\": \"\\\\\\\\.\\\\PHYSICALDRIVE0\",\n            \"type\": \"HD\",\n            \"name\": \"ST9640320AS\",\n            \"vendor\": \"Seagate\",\n            \"size\": 640132416000,\n            \"bytesPerSector\": 512,\n            \"totalCylinders\": 77825,\n            \"totalHeads\": 255,\n            \"totalSectors\": 1250258625,\n            \"totalTracks\": 19845375,\n            \"tracksPerCylinder\": 255,\n            \"sectorsPerTrack\": 63,\n            \"firmwareRevision\": \"0002HPM1\",\n            \"serialNum\": \"5WX2KXLV\",\n            \"interfaceType\": \"SATA\",\n            \"smartStatus\": \"Ok\",\n            \"temperature\": null\n        },\n        {\n            \"device\": \"\\\\\\\\.\\\\PHYSICALDRIVE2\",\n            \"type\": \"SSD\",\n            \"name\": \"Samsung SSD 850 EVO 500GB\",\n            \"vendor\": \"Samsung\",\n            \"size\": 500105249280,\n            \"bytesPerSector\": 512,\n            \"totalCylinders\": 60801,\n            \"totalHeads\": 255,\n            \"totalSectors\": 976768065,\n            \"totalTracks\": 15504255,\n            \"tracksPerCylinder\": 255,\n            \"sectorsPerTrack\": 63,\n            \"firmwareRevision\": \"EMT02B6Q\",\n            \"serialNum\": \"S2RANX0H825794M\",\n            \"interfaceType\": \"SATA\",\n            \"smartStatus\": \"Ok\",\n            \"temperature\": null\n        },\n        {\n            \"device\": \"\\\\\\\\.\\\\PHYSICALDRIVE3\",\n            \"type\": \"SSD\",\n            \"name\": \"Samsung SSD 970 EVO Plus 1TB\",\n            \"vendor\": \"Samsung\",\n            \"size\": 1000202273280,\n            \"bytesPerSector\": 512,\n            \"totalCylinders\": 121601,\n            \"totalHeads\": 255,\n            \"totalSectors\": 1953520065,\n            \"totalTracks\": 31008255,\n            \"tracksPerCylinder\": 255,\n            \"sectorsPerTrack\": 63,\n            \"firmwareRevision\": \"2B2Q\",\n            \"serialNum\": \"0025_3851_0141_DF22.\",\n            \"interfaceType\": \"NVMe\",\n            \"smartStatus\": \"Ok\",\n            \"temperature\": null\n        }\n    ]\n}","output":"json","x":260,"y":740,"wires":[["6644ed21fe795c03"]]},{"id":"839c0b83008329d3","type":"inject","z":"bec7048b1f74f182","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":100,"y":740,"wires":[["d4ae6622b4e4681c"]]}]

The function works and I can output the results to the console but when I try to modify it to send the output to msg.payload the code fails.

Can some one show me how to send the console.log output as a message?

thx

I frequently see console.log in snippets of javascript online. I don't know where it logs to when called in Node-red functions. I always replace this with node.warn() to output to the editor debug panel.

Doing this in your flow I see hundreds of data snippets output individually, eg

diskLayout.4.totalTracks: 31008255

To send data as a message you should build a json object with a payload and call node.send(). Potentially something like this.

const allKeyValuePairs = getAllKeyValuePairs(myJsonObject);
allKeyValuePairs.forEach(item => {
  const key = item.path
  const value = item.value
let newmsg = {"payload": {key: value} }
node.send(newmsg)
//node.warn(`${item.path}: ${item.value}`);
});

I can't actually see a good reason to break the input data up like this, but if I did want to, I'd consider using cascading Split nodes rather than writing a function.

@jbudd

Yes you are correct that this is generated from AI. I did not realize the function would output one message per key/value. To give you some context I am trying to come up with a reusable function that I can pass to a UI template node to auto populate key/value pairs.

For example when I send the template output to UI template node with:

<script>
    (function(scope) {
        scope.$watch('msg.payload', function(data) {
            const container = document.getElementById("container");
            
            while (container.firstChild) {
                container.removeChild(container.firstChild);
            }

            for (const key in data) {
            const element = document.createElement("p");
            element.textContent = `${key}: ${data[key]}`;
            container.appendChild(element);
            }

        });
    })(scope);

</script>
<h2>System Info </h2>
<div id="container"></div>

The code will not iterate through all the json objects. See below:

I got around it by using specific objects but I would like to be able to have the code iterate through the entire object for input in the UI Template.

thx

Unfortunately my brain always freezes up when confronted by javascript in a UI template, it's all too abstracted to deal with.

I can start with a specific input message such as in your first post, and work out how to get a defined layout of items in a [diagram of the] template, but that's about all I can manage :neutral_face:

You can try convert the json to yaml, and then just show the string in an Markdown node. Then you dont have the json clutter

[{"id":"d4f3fe628a423909","type":"yaml","z":"617486c48a1f4814","property":"payload","name":"","x":470,"y":260,"wires":[["95fdd7f5981bc3b8","582dc7255d0a6983"]]},{"id":"582dc7255d0a6983","type":"ui-markdown","z":"617486c48a1f4814","group":"aeb58423b25112a4","name":"","order":1,"width":0,"height":0,"content":"```\n{{msg?.payload}}\n```","className":"","x":630,"y":260,"wires":[[]]},{"id":"d4ae6622b4e4681c","type":"template","z":"617486c48a1f4814","name":"","field":"payload","fieldType":"msg","format":"json","syntax":"plain","template":"{\n    \"version\": \"5.21.22\",\n    \"system\": {\n        \"manufacturer\": \"Gigabyte Technology Co., Ltd.\",\n        \"model\": \"Z390 AORUS PRO WIFI\",\n        \"version\": \"Default string\",\n        \"serial\": \"Default string\",\n        \"uuid\": \"032e02b4-0499-058e-e506-470700080009\",\n        \"sku\": \"Default string\",\n        \"virtual\": false\n    },\n    \"bios\": {\n        \"vendor\": \"American Megatrends Inc.\",\n        \"version\": \"F10\",\n        \"releaseDate\": \"2019-06-04\",\n        \"revision\": \"\",\n        \"serial\": \"\"\n    },\n    \"baseboard\": {\n        \"manufacturer\": \"Gigabyte Technology Co., Ltd.\",\n        \"model\": \"Z390 AORUS PRO WIFI-CF\",\n        \"version\": \"x.x\",\n        \"serial\": \"\",\n        \"assetTag\": \"\",\n        \"memMax\": 68719476736,\n        \"memSlots\": 4\n    },\n    \"chassis\": {\n        \"manufacturer\": \"\",\n        \"model\": \"\",\n        \"type\": \"Desktop\",\n        \"version\": \"\",\n        \"serial\": \"\",\n        \"assetTag\": \"\",\n        \"sku\": \"\"\n    },\n    \"os\": {\n        \"platform\": \"Windows\",\n        \"distro\": \"Microsoft Windows 11 Pro\",\n        \"release\": \"10.0.26120\",\n        \"codename\": \"\",\n        \"kernel\": \"10.0.26120\",\n        \"arch\": \"x64\",\n        \"hostname\": \"w8be-prod\",\n        \"fqdn\": \"W8BE-PROD\",\n        \"codepage\": \"437\",\n        \"logofile\": \"windows\",\n        \"serial\": \"00330-80021-43272-AA568\",\n        \"build\": \"26120\",\n        \"servicepack\": \"0.0\",\n        \"uefi\": true,\n        \"hypervisor\": false,\n        \"remoteSession\": false\n    },\n    \"uuid\": {\n        \"os\": \"596d850e-1cbc-456d-81c8-9dbeb723a679\",\n        \"hardware\": \"032e02b4-0499-058e-e506-470700080009\",\n        \"macs\": [\n            \"b4:2e:99:8e:e5:47\"\n        ]\n    },\n    \"versions\": {\n        \"kernel\": \"10.0.26120\",\n        \"openssl\": \"3.0.13+quic\",\n        \"systemOpenssl\": \"\",\n        \"systemOpensslLib\": \"\",\n        \"node\": \"20.15.0\",\n        \"v8\": \"11.3.244.8-node.23\",\n        \"npm\": \"10.8.1\",\n        \"yarn\": \"\",\n        \"pm2\": \"\",\n        \"gulp\": \"\",\n        \"grunt\": \"\",\n        \"git\": \"2.47.0.windows.2\",\n        \"tsc\": \"\",\n        \"mysql\": \"\",\n        \"redis\": \"\",\n        \"mongodb\": \"\",\n        \"apache\": \"\",\n        \"nginx\": \"\",\n        \"php\": \"\",\n        \"docker\": \"\",\n        \"postfix\": \"\",\n        \"postgresql\": \"\",\n        \"perl\": \"\",\n        \"python\": \"3.11.0\",\n        \"python3\": \"\",\n        \"pip\": \"22.3\",\n        \"pip3\": \"22.3\",\n        \"java\": \"\",\n        \"gcc\": \"\",\n        \"virtualbox\": \"\",\n        \"bash\": \"\",\n        \"zsh\": \"\",\n        \"fish\": \"\",\n        \"powershell\": \"5.1.26100.2200:\",\n        \"dotnet\": \"4.8.09032\"\n    },\n    \"cpu\": {\n        \"manufacturer\": \"Intel\",\n        \"brand\": \"Core™ i9-9900K\",\n        \"vendor\": \"GenuineIntel\",\n        \"family\": \"6\",\n        \"model\": \"158\",\n        \"stepping\": \"13\",\n        \"revision\": \"\",\n        \"voltage\": \"\",\n        \"speed\": 3.6,\n        \"speedMin\": 3.6,\n        \"speedMax\": 3.6,\n        \"governor\": \"\",\n        \"cores\": 16,\n        \"physicalCores\": 8,\n        \"performanceCores\": 16,\n        \"efficiencyCores\": 0,\n        \"processors\": 1,\n        \"socket\": \"LGA1151\",\n        \"flags\": \"de pse tsc msr mce sep mtrr mca cmov psn clfsh ds acpi mmx fxsr sse sse2 ss htt tm ia64 pbe\",\n        \"virtualization\": false,\n        \"cache\": {\n            \"l1d\": 256,\n            \"l1i\": 256,\n            \"l2\": 2097152,\n            \"l3\": 16777216\n        }\n    },\n    \"graphics\": {\n        \"controllers\": [\n            {\n                \"vendor\": \"Advanced Micro Devices, Inc.\",\n                \"model\": \"ASUS Radeon RX 580 Series\",\n                \"bus\": \"PCI\",\n                \"vram\": 8192,\n                \"vramDynamic\": true,\n                \"subDeviceId\": \"2378148C\"\n            }\n        ],\n        \"displays\": [\n            {\n                \"vendor\": \"(Standard monitor types)\",\n                \"model\": \"Generic PnP Monitor\",\n                \"deviceName\": \"\\\\\\\\.\\\\DISPLAY2\",\n                \"main\": true,\n                \"builtin\": false,\n                \"connection\": \"DP\",\n                \"resolutionX\": 3072,\n                \"resolutionY\": 1728,\n                \"sizeX\": 53,\n                \"sizeY\": 30,\n                \"pixelDepth\": \"32\",\n                \"currentResX\": 3072,\n                \"currentResY\": 1728,\n                \"positionX\": 0,\n                \"positionY\": 0,\n                \"currentRefreshRate\": 60\n            },\n            {\n                \"vendor\": \"\",\n                \"model\": \"\",\n                \"deviceName\": \"\\\\\\\\.\\\\DISPLAY1\",\n                \"main\": false,\n                \"builtin\": false,\n                \"connection\": \"DP\",\n                \"resolutionX\": 1920,\n                \"resolutionY\": 1080,\n                \"sizeX\": 70,\n                \"sizeY\": 40,\n                \"pixelDepth\": \"32\",\n                \"currentResX\": 1920,\n                \"currentResY\": 1080,\n                \"positionX\": -1920,\n                \"positionY\": 0,\n                \"currentRefreshRate\": 60\n            },\n            {\n                \"vendor\": \"\",\n                \"model\": \"\",\n                \"deviceName\": \"\\\\\\\\.\\\\DISPLAY3\",\n                \"main\": false,\n                \"builtin\": false,\n                \"connection\": \"DP\",\n                \"resolutionX\": 2560,\n                \"resolutionY\": 1440,\n                \"sizeX\": 53,\n                \"sizeY\": 30,\n                \"pixelDepth\": \"32\",\n                \"currentResX\": 2560,\n                \"currentResY\": 1440,\n                \"positionX\": 3840,\n                \"positionY\": 0,\n                \"currentRefreshRate\": 60\n            }\n        ]\n    },\n    \"net\": [\n        {\n            \"iface\": \"Eth0\",\n            \"ifaceName\": \"Intel(R) Ethernet Connection (7) I219-V\",\n            \"default\": true,\n            \"ip4\": \"192.168.0.64\",\n            \"ip4subnet\": \"255.255.255.0\",\n            \"ip6\": \"2601:151:8300:e9c:9673:3210:7700:1c43\",\n            \"ip6subnet\": \"ffff:ffff:ffff:ffff::\",\n            \"mac\": \"b4:2e:99:8e:e5:47\",\n            \"internal\": false,\n            \"virtual\": false,\n            \"operstate\": \"up\",\n            \"type\": \"wired\",\n            \"duplex\": \"\",\n            \"mtu\": \"\",\n            \"speed\": 1000,\n            \"dhcp\": true,\n            \"dnsSuffix\": \"hsd1.wv.comcast.net\",\n            \"ieee8021xAuth\": \"Not defined\",\n            \"ieee8021xState\": \"Disabled\",\n            \"carrierChanges\": 0\n        },\n        {\n            \"iface\": \"Loopback Pseudo-Interface 1\",\n            \"ifaceName\": \"Loopback Pseudo-Interface 1\",\n            \"default\": false,\n            \"ip4\": \"127.0.0.1\",\n            \"ip4subnet\": \"255.0.0.0\",\n            \"ip6\": \"::1\",\n            \"ip6subnet\": \"ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff\",\n            \"mac\": \"00:00:00:00:00:00\",\n            \"internal\": true,\n            \"virtual\": false,\n            \"operstate\": \"down\",\n            \"type\": \"\",\n            \"duplex\": \"\",\n            \"mtu\": \"\",\n            \"speed\": null,\n            \"dhcp\": false,\n            \"dnsSuffix\": \"\",\n            \"ieee8021xAuth\": \"Not defined\",\n            \"ieee8021xState\": \"Disabled\",\n            \"carrierChanges\": 0\n        },\n        {\n            \"iface\": \"Wi-Fi\",\n            \"ifaceName\": \"Intel(R) Wireless-AC 9560 160MHz\",\n            \"default\": false,\n            \"ip4\": \"\",\n            \"ip4subnet\": \"\",\n            \"ip6\": \"\",\n            \"ip6subnet\": \"\",\n            \"mac\": \"\",\n            \"virtual\": false,\n            \"operstate\": \"down\",\n            \"type\": \"wireless\",\n            \"duplex\": \"\",\n            \"mtu\": \"\",\n            \"speed\": null,\n            \"dhcp\": true,\n            \"dnsSuffix\": \"\",\n            \"ieee8021xAuth\": \"Not defined\",\n            \"ieee8021xState\": \"Disabled\",\n            \"carrierChanges\": 0\n        }\n    ],\n    \"memLayout\": [\n        {\n            \"size\": 17179869184,\n            \"bank\": \"BANK 1\",\n            \"type\": \"DDR4\",\n            \"ecc\": false,\n            \"clockSpeed\": 3200,\n            \"formFactor\": \"DIMM\",\n            \"manufacturer\": \"04CD\",\n            \"partNum\": \"F4-3200C16-16GVK\",\n            \"serialNum\": \"00000000\",\n            \"voltageConfigured\": 1.2,\n            \"voltageMin\": 1.2,\n            \"voltageMax\": 1.2\n        },\n        {\n            \"size\": 17179869184,\n            \"bank\": \"BANK 3\",\n            \"type\": \"DDR4\",\n            \"ecc\": false,\n            \"clockSpeed\": 3200,\n            \"formFactor\": \"DIMM\",\n            \"manufacturer\": \"04CD\",\n            \"partNum\": \"F4-3200C16-16GVK\",\n            \"serialNum\": \"00000000\",\n            \"voltageConfigured\": 1.2,\n            \"voltageMin\": 1.2,\n            \"voltageMax\": 1.2\n        }\n    ],\n    \"diskLayout\": [\n        {\n            \"device\": \"\\\\\\\\.\\\\PHYSICALDRIVE4\",\n            \"type\": \"SSD\",\n            \"name\": \"SPCC M.2 PCIe SSD\",\n            \"vendor\": \"\",\n            \"size\": 256052966400,\n            \"bytesPerSector\": 512,\n            \"totalCylinders\": 31130,\n            \"totalHeads\": 255,\n            \"totalSectors\": 500103450,\n            \"totalTracks\": 7938150,\n            \"tracksPerCylinder\": 255,\n            \"sectorsPerTrack\": 63,\n            \"firmwareRevision\": \"S0614B0\",\n            \"serialNum\": \"0100_0000_0000_0000.\",\n            \"interfaceType\": \"NVMe\",\n            \"smartStatus\": \"Ok\",\n            \"temperature\": null\n        },\n        {\n            \"device\": \"\\\\\\\\.\\\\PHYSICALDRIVE1\",\n            \"type\": \"HD\",\n            \"name\": \"ST2000DM001-1CH164\",\n            \"vendor\": \"Seagate\",\n            \"size\": 2000396321280,\n            \"bytesPerSector\": 512,\n            \"totalCylinders\": 243201,\n            \"totalHeads\": 255,\n            \"totalSectors\": 3907024065,\n            \"totalTracks\": 62016255,\n            \"tracksPerCylinder\": 255,\n            \"sectorsPerTrack\": 63,\n            \"firmwareRevision\": \"HP36\",\n            \"serialNum\": \"Z1E8L0YY\",\n            \"interfaceType\": \"SATA\",\n            \"smartStatus\": \"Ok\",\n            \"temperature\": null\n        },\n        {\n            \"device\": \"\\\\\\\\.\\\\PHYSICALDRIVE0\",\n            \"type\": \"HD\",\n            \"name\": \"ST9640320AS\",\n            \"vendor\": \"Seagate\",\n            \"size\": 640132416000,\n            \"bytesPerSector\": 512,\n            \"totalCylinders\": 77825,\n            \"totalHeads\": 255,\n            \"totalSectors\": 1250258625,\n            \"totalTracks\": 19845375,\n            \"tracksPerCylinder\": 255,\n            \"sectorsPerTrack\": 63,\n            \"firmwareRevision\": \"0002HPM1\",\n            \"serialNum\": \"5WX2KXLV\",\n            \"interfaceType\": \"SATA\",\n            \"smartStatus\": \"Ok\",\n            \"temperature\": null\n        },\n        {\n            \"device\": \"\\\\\\\\.\\\\PHYSICALDRIVE2\",\n            \"type\": \"SSD\",\n            \"name\": \"Samsung SSD 850 EVO 500GB\",\n            \"vendor\": \"Samsung\",\n            \"size\": 500105249280,\n            \"bytesPerSector\": 512,\n            \"totalCylinders\": 60801,\n            \"totalHeads\": 255,\n            \"totalSectors\": 976768065,\n            \"totalTracks\": 15504255,\n            \"tracksPerCylinder\": 255,\n            \"sectorsPerTrack\": 63,\n            \"firmwareRevision\": \"EMT02B6Q\",\n            \"serialNum\": \"S2RANX0H825794M\",\n            \"interfaceType\": \"SATA\",\n            \"smartStatus\": \"Ok\",\n            \"temperature\": null\n        },\n        {\n            \"device\": \"\\\\\\\\.\\\\PHYSICALDRIVE3\",\n            \"type\": \"SSD\",\n            \"name\": \"Samsung SSD 970 EVO Plus 1TB\",\n            \"vendor\": \"Samsung\",\n            \"size\": 1000202273280,\n            \"bytesPerSector\": 512,\n            \"totalCylinders\": 121601,\n            \"totalHeads\": 255,\n            \"totalSectors\": 1953520065,\n            \"totalTracks\": 31008255,\n            \"tracksPerCylinder\": 255,\n            \"sectorsPerTrack\": 63,\n            \"firmwareRevision\": \"2B2Q\",\n            \"serialNum\": \"0025_3851_0141_DF22.\",\n            \"interfaceType\": \"NVMe\",\n            \"smartStatus\": \"Ok\",\n            \"temperature\": null\n        }\n    ]\n}","output":"json","x":320,"y":260,"wires":[["d4f3fe628a423909"]]},{"id":"839c0b83008329d3","type":"inject","z":"617486c48a1f4814","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":160,"y":260,"wires":[["d4ae6622b4e4681c"]]},{"id":"aeb58423b25112a4","type":"ui-group","name":"Group Name","page":"a3c04197f8e84242","width":6,"height":1,"order":1,"showTitle":true,"className":"","visible":"true","disabled":"false","groupType":"default"},{"id":"a3c04197f8e84242","type":"ui-page","name":"Test","ui":"593e5289bfb8381f","path":"/test","icon":"home","layout":"grid","theme":"8320d2deb29c6eb8","breakpoints":[{"name":"Default","px":"0","cols":"3"},{"name":"Tablet","px":"576","cols":"6"},{"name":"Small Desktop","px":"768","cols":"9"},{"name":"Desktop","px":"1024","cols":"12"}],"order":3,"className":"","visible":"true","disabled":"false"},{"id":"593e5289bfb8381f","type":"ui-base","name":"Node-RED Dashboard","path":"/dashboard","includeClientData":true,"acceptsClientConfig":["ui-template","ui-control","ui-chart","ui-table","ui-dropdown","ui-gauge","ui-notification","ui-markdown","ui-text","ui-switch","ui-slider","ui-radio-group","ui-button-group","ui-button","ui-file-input","ui-text-input","ui-form","ui-number-input","ui-audio"],"showPathInSidebar":false,"headerContent":"page","navigationStyle":"default","titleBarStyle":"default","notificationDisplayTime":5},{"id":"8320d2deb29c6eb8","type":"ui-theme","name":"Default Compact","colors":{"surface":"#ffffff","primary":"#0094ce","bgPage":"#eeeeee","groupBg":"#ffffff","groupOutline":"#cccccc"},"sizes":{"pagePadding":"12px","groupGap":"12px","groupBorderRadius":"4px","widgetGap":"12px","density":"comfortable"}}]
2 Likes

If i understand correctly, this may be what you require

function getAllKeyValuePairs(obj, path = '') {
  const results = [];

  for (const key in obj) {
    if (obj.hasOwnProperty(key)) {
      const currentPath = path ? `${path}.${key}` : key;
      const value = obj[key];

      if (typeof value === 'object' && value !== null) {
        results.push(...getAllKeyValuePairs(value, currentPath));
      } else {
        results.push({ [currentPath]: value });
      }
    }
  }

  return results;
}



msg.payload = getAllKeyValuePairs(msg.payload);
return msg

Or may be you need a object?

function getAllKeyValuePairs(obj, path = '') {
  let results = {};

  for (const key in obj) {
    if (obj.hasOwnProperty(key)) {
      const currentPath = path ? `${path}.${key}` : key;
      const value = obj[key];

      if (typeof value === 'object' && value !== null) {
        results =  Object.assign(results, getAllKeyValuePairs(value, currentPath));
      } else {
        results[currentPath] =  value;
      }
    }
  }

  return results;
}



msg.payload = getAllKeyValuePairs(msg.payload);
return msg

Or possibly a string with each item on a new line then @kitori suggestion would be a good solution.

Implementation without function node. The path is an array, and after the split nodes the current key(or array index) is pushed to this property.

Since i dont now in advance how many elements i get, the join node wait for 100ms until it join the messages. Is there a better option?

[{"id":"95fdd7f5981bc3b8","type":"debug","z":"617486c48a1f4814","name":"debug 35","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1160,"y":520,"wires":[]},{"id":"d4ae6622b4e4681c","type":"template","z":"617486c48a1f4814","name":"","field":"payload","fieldType":"msg","format":"json","syntax":"plain","template":"{\n    \"version\": \"5.21.22\",\n    \"system\": {\n        \"manufacturer\": \"Gigabyte Technology Co., Ltd.\",\n        \"model\": \"Z390 AORUS PRO WIFI\",\n        \"version\": \"Default string\",\n        \"serial\": \"Default string\",\n        \"uuid\": \"032e02b4-0499-058e-e506-470700080009\",\n        \"sku\": \"Default string\",\n        \"virtual\": false\n    },\n    \"bios\": {\n        \"vendor\": \"American Megatrends Inc.\",\n        \"version\": \"F10\",\n        \"releaseDate\": \"2019-06-04\",\n        \"revision\": \"\",\n        \"serial\": \"\"\n    },\n    \"baseboard\": {\n        \"manufacturer\": \"Gigabyte Technology Co., Ltd.\",\n        \"model\": \"Z390 AORUS PRO WIFI-CF\",\n        \"version\": \"x.x\",\n        \"serial\": \"\",\n        \"assetTag\": \"\",\n        \"memMax\": 68719476736,\n        \"memSlots\": 4\n    },\n    \"chassis\": {\n        \"manufacturer\": \"\",\n        \"model\": \"\",\n        \"type\": \"Desktop\",\n        \"version\": \"\",\n        \"serial\": \"\",\n        \"assetTag\": \"\",\n        \"sku\": \"\"\n    },\n    \"os\": {\n        \"platform\": \"Windows\",\n        \"distro\": \"Microsoft Windows 11 Pro\",\n        \"release\": \"10.0.26120\",\n        \"codename\": \"\",\n        \"kernel\": \"10.0.26120\",\n        \"arch\": \"x64\",\n        \"hostname\": \"w8be-prod\",\n        \"fqdn\": \"W8BE-PROD\",\n        \"codepage\": \"437\",\n        \"logofile\": \"windows\",\n        \"serial\": \"00330-80021-43272-AA568\",\n        \"build\": \"26120\",\n        \"servicepack\": \"0.0\",\n        \"uefi\": true,\n        \"hypervisor\": false,\n        \"remoteSession\": false\n    },\n    \"uuid\": {\n        \"os\": \"596d850e-1cbc-456d-81c8-9dbeb723a679\",\n        \"hardware\": \"032e02b4-0499-058e-e506-470700080009\",\n        \"macs\": [\n            \"b4:2e:99:8e:e5:47\"\n        ]\n    },\n    \"versions\": {\n        \"kernel\": \"10.0.26120\",\n        \"openssl\": \"3.0.13+quic\",\n        \"systemOpenssl\": \"\",\n        \"systemOpensslLib\": \"\",\n        \"node\": \"20.15.0\",\n        \"v8\": \"11.3.244.8-node.23\",\n        \"npm\": \"10.8.1\",\n        \"yarn\": \"\",\n        \"pm2\": \"\",\n        \"gulp\": \"\",\n        \"grunt\": \"\",\n        \"git\": \"2.47.0.windows.2\",\n        \"tsc\": \"\",\n        \"mysql\": \"\",\n        \"redis\": \"\",\n        \"mongodb\": \"\",\n        \"apache\": \"\",\n        \"nginx\": \"\",\n        \"php\": \"\",\n        \"docker\": \"\",\n        \"postfix\": \"\",\n        \"postgresql\": \"\",\n        \"perl\": \"\",\n        \"python\": \"3.11.0\",\n        \"python3\": \"\",\n        \"pip\": \"22.3\",\n        \"pip3\": \"22.3\",\n        \"java\": \"\",\n        \"gcc\": \"\",\n        \"virtualbox\": \"\",\n        \"bash\": \"\",\n        \"zsh\": \"\",\n        \"fish\": \"\",\n        \"powershell\": \"5.1.26100.2200:\",\n        \"dotnet\": \"4.8.09032\"\n    },\n    \"cpu\": {\n        \"manufacturer\": \"Intel\",\n        \"brand\": \"Core™ i9-9900K\",\n        \"vendor\": \"GenuineIntel\",\n        \"family\": \"6\",\n        \"model\": \"158\",\n        \"stepping\": \"13\",\n        \"revision\": \"\",\n        \"voltage\": \"\",\n        \"speed\": 3.6,\n        \"speedMin\": 3.6,\n        \"speedMax\": 3.6,\n        \"governor\": \"\",\n        \"cores\": 16,\n        \"physicalCores\": 8,\n        \"performanceCores\": 16,\n        \"efficiencyCores\": 0,\n        \"processors\": 1,\n        \"socket\": \"LGA1151\",\n        \"flags\": \"de pse tsc msr mce sep mtrr mca cmov psn clfsh ds acpi mmx fxsr sse sse2 ss htt tm ia64 pbe\",\n        \"virtualization\": false,\n        \"cache\": {\n            \"l1d\": 256,\n            \"l1i\": 256,\n            \"l2\": 2097152,\n            \"l3\": 16777216\n        }\n    },\n    \"graphics\": {\n        \"controllers\": [\n            {\n                \"vendor\": \"Advanced Micro Devices, Inc.\",\n                \"model\": \"ASUS Radeon RX 580 Series\",\n                \"bus\": \"PCI\",\n                \"vram\": 8192,\n                \"vramDynamic\": true,\n                \"subDeviceId\": \"2378148C\"\n            }\n        ],\n        \"displays\": [\n            {\n                \"vendor\": \"(Standard monitor types)\",\n                \"model\": \"Generic PnP Monitor\",\n                \"deviceName\": \"\\\\\\\\.\\\\DISPLAY2\",\n                \"main\": true,\n                \"builtin\": false,\n                \"connection\": \"DP\",\n                \"resolutionX\": 3072,\n                \"resolutionY\": 1728,\n                \"sizeX\": 53,\n                \"sizeY\": 30,\n                \"pixelDepth\": \"32\",\n                \"currentResX\": 3072,\n                \"currentResY\": 1728,\n                \"positionX\": 0,\n                \"positionY\": 0,\n                \"currentRefreshRate\": 60\n            },\n            {\n                \"vendor\": \"\",\n                \"model\": \"\",\n                \"deviceName\": \"\\\\\\\\.\\\\DISPLAY1\",\n                \"main\": false,\n                \"builtin\": false,\n                \"connection\": \"DP\",\n                \"resolutionX\": 1920,\n                \"resolutionY\": 1080,\n                \"sizeX\": 70,\n                \"sizeY\": 40,\n                \"pixelDepth\": \"32\",\n                \"currentResX\": 1920,\n                \"currentResY\": 1080,\n                \"positionX\": -1920,\n                \"positionY\": 0,\n                \"currentRefreshRate\": 60\n            },\n            {\n                \"vendor\": \"\",\n                \"model\": \"\",\n                \"deviceName\": \"\\\\\\\\.\\\\DISPLAY3\",\n                \"main\": false,\n                \"builtin\": false,\n                \"connection\": \"DP\",\n                \"resolutionX\": 2560,\n                \"resolutionY\": 1440,\n                \"sizeX\": 53,\n                \"sizeY\": 30,\n                \"pixelDepth\": \"32\",\n                \"currentResX\": 2560,\n                \"currentResY\": 1440,\n                \"positionX\": 3840,\n                \"positionY\": 0,\n                \"currentRefreshRate\": 60\n            }\n        ]\n    },\n    \"net\": [\n        {\n            \"iface\": \"Eth0\",\n            \"ifaceName\": \"Intel(R) Ethernet Connection (7) I219-V\",\n            \"default\": true,\n            \"ip4\": \"192.168.0.64\",\n            \"ip4subnet\": \"255.255.255.0\",\n            \"ip6\": \"2601:151:8300:e9c:9673:3210:7700:1c43\",\n            \"ip6subnet\": \"ffff:ffff:ffff:ffff::\",\n            \"mac\": \"b4:2e:99:8e:e5:47\",\n            \"internal\": false,\n            \"virtual\": false,\n            \"operstate\": \"up\",\n            \"type\": \"wired\",\n            \"duplex\": \"\",\n            \"mtu\": \"\",\n            \"speed\": 1000,\n            \"dhcp\": true,\n            \"dnsSuffix\": \"hsd1.wv.comcast.net\",\n            \"ieee8021xAuth\": \"Not defined\",\n            \"ieee8021xState\": \"Disabled\",\n            \"carrierChanges\": 0\n        },\n        {\n            \"iface\": \"Loopback Pseudo-Interface 1\",\n            \"ifaceName\": \"Loopback Pseudo-Interface 1\",\n            \"default\": false,\n            \"ip4\": \"127.0.0.1\",\n            \"ip4subnet\": \"255.0.0.0\",\n            \"ip6\": \"::1\",\n            \"ip6subnet\": \"ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff\",\n            \"mac\": \"00:00:00:00:00:00\",\n            \"internal\": true,\n            \"virtual\": false,\n            \"operstate\": \"down\",\n            \"type\": \"\",\n            \"duplex\": \"\",\n            \"mtu\": \"\",\n            \"speed\": null,\n            \"dhcp\": false,\n            \"dnsSuffix\": \"\",\n            \"ieee8021xAuth\": \"Not defined\",\n            \"ieee8021xState\": \"Disabled\",\n            \"carrierChanges\": 0\n        },\n        {\n            \"iface\": \"Wi-Fi\",\n            \"ifaceName\": \"Intel(R) Wireless-AC 9560 160MHz\",\n            \"default\": false,\n            \"ip4\": \"\",\n            \"ip4subnet\": \"\",\n            \"ip6\": \"\",\n            \"ip6subnet\": \"\",\n            \"mac\": \"\",\n            \"virtual\": false,\n            \"operstate\": \"down\",\n            \"type\": \"wireless\",\n            \"duplex\": \"\",\n            \"mtu\": \"\",\n            \"speed\": null,\n            \"dhcp\": true,\n            \"dnsSuffix\": \"\",\n            \"ieee8021xAuth\": \"Not defined\",\n            \"ieee8021xState\": \"Disabled\",\n            \"carrierChanges\": 0\n        }\n    ],\n    \"memLayout\": [\n        {\n            \"size\": 17179869184,\n            \"bank\": \"BANK 1\",\n            \"type\": \"DDR4\",\n            \"ecc\": false,\n            \"clockSpeed\": 3200,\n            \"formFactor\": \"DIMM\",\n            \"manufacturer\": \"04CD\",\n            \"partNum\": \"F4-3200C16-16GVK\",\n            \"serialNum\": \"00000000\",\n            \"voltageConfigured\": 1.2,\n            \"voltageMin\": 1.2,\n            \"voltageMax\": 1.2\n        },\n        {\n            \"size\": 17179869184,\n            \"bank\": \"BANK 3\",\n            \"type\": \"DDR4\",\n            \"ecc\": false,\n            \"clockSpeed\": 3200,\n            \"formFactor\": \"DIMM\",\n            \"manufacturer\": \"04CD\",\n            \"partNum\": \"F4-3200C16-16GVK\",\n            \"serialNum\": \"00000000\",\n            \"voltageConfigured\": 1.2,\n            \"voltageMin\": 1.2,\n            \"voltageMax\": 1.2\n        }\n    ],\n    \"diskLayout\": [\n        {\n            \"device\": \"\\\\\\\\.\\\\PHYSICALDRIVE4\",\n            \"type\": \"SSD\",\n            \"name\": \"SPCC M.2 PCIe SSD\",\n            \"vendor\": \"\",\n            \"size\": 256052966400,\n            \"bytesPerSector\": 512,\n            \"totalCylinders\": 31130,\n            \"totalHeads\": 255,\n            \"totalSectors\": 500103450,\n            \"totalTracks\": 7938150,\n            \"tracksPerCylinder\": 255,\n            \"sectorsPerTrack\": 63,\n            \"firmwareRevision\": \"S0614B0\",\n            \"serialNum\": \"0100_0000_0000_0000.\",\n            \"interfaceType\": \"NVMe\",\n            \"smartStatus\": \"Ok\",\n            \"temperature\": null\n        },\n        {\n            \"device\": \"\\\\\\\\.\\\\PHYSICALDRIVE1\",\n            \"type\": \"HD\",\n            \"name\": \"ST2000DM001-1CH164\",\n            \"vendor\": \"Seagate\",\n            \"size\": 2000396321280,\n            \"bytesPerSector\": 512,\n            \"totalCylinders\": 243201,\n            \"totalHeads\": 255,\n            \"totalSectors\": 3907024065,\n            \"totalTracks\": 62016255,\n            \"tracksPerCylinder\": 255,\n            \"sectorsPerTrack\": 63,\n            \"firmwareRevision\": \"HP36\",\n            \"serialNum\": \"Z1E8L0YY\",\n            \"interfaceType\": \"SATA\",\n            \"smartStatus\": \"Ok\",\n            \"temperature\": null\n        },\n        {\n            \"device\": \"\\\\\\\\.\\\\PHYSICALDRIVE0\",\n            \"type\": \"HD\",\n            \"name\": \"ST9640320AS\",\n            \"vendor\": \"Seagate\",\n            \"size\": 640132416000,\n            \"bytesPerSector\": 512,\n            \"totalCylinders\": 77825,\n            \"totalHeads\": 255,\n            \"totalSectors\": 1250258625,\n            \"totalTracks\": 19845375,\n            \"tracksPerCylinder\": 255,\n            \"sectorsPerTrack\": 63,\n            \"firmwareRevision\": \"0002HPM1\",\n            \"serialNum\": \"5WX2KXLV\",\n            \"interfaceType\": \"SATA\",\n            \"smartStatus\": \"Ok\",\n            \"temperature\": null\n        },\n        {\n            \"device\": \"\\\\\\\\.\\\\PHYSICALDRIVE2\",\n            \"type\": \"SSD\",\n            \"name\": \"Samsung SSD 850 EVO 500GB\",\n            \"vendor\": \"Samsung\",\n            \"size\": 500105249280,\n            \"bytesPerSector\": 512,\n            \"totalCylinders\": 60801,\n            \"totalHeads\": 255,\n            \"totalSectors\": 976768065,\n            \"totalTracks\": 15504255,\n            \"tracksPerCylinder\": 255,\n            \"sectorsPerTrack\": 63,\n            \"firmwareRevision\": \"EMT02B6Q\",\n            \"serialNum\": \"S2RANX0H825794M\",\n            \"interfaceType\": \"SATA\",\n            \"smartStatus\": \"Ok\",\n            \"temperature\": null\n        },\n        {\n            \"device\": \"\\\\\\\\.\\\\PHYSICALDRIVE3\",\n            \"type\": \"SSD\",\n            \"name\": \"Samsung SSD 970 EVO Plus 1TB\",\n            \"vendor\": \"Samsung\",\n            \"size\": 1000202273280,\n            \"bytesPerSector\": 512,\n            \"totalCylinders\": 121601,\n            \"totalHeads\": 255,\n            \"totalSectors\": 1953520065,\n            \"totalTracks\": 31008255,\n            \"tracksPerCylinder\": 255,\n            \"sectorsPerTrack\": 63,\n            \"firmwareRevision\": \"2B2Q\",\n            \"serialNum\": \"0025_3851_0141_DF22.\",\n            \"interfaceType\": \"NVMe\",\n            \"smartStatus\": \"Ok\",\n            \"temperature\": null\n        }\n    ]\n}","output":"json","x":340,"y":520,"wires":[["7c6067511bc5335d"]]},{"id":"839c0b83008329d3","type":"inject","z":"617486c48a1f4814","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":180,"y":520,"wires":[["d4ae6622b4e4681c"]]},{"id":"7afccf9e887d2f3f","type":"split","z":"617486c48a1f4814","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","property":"payload","x":250,"y":200,"wires":[["7a9981e248c78dad"]]},{"id":"7c6067511bc5335d","type":"change","z":"617486c48a1f4814","name":"","rules":[{"t":"set","p":"path","pt":"msg","to":"[]","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":510,"y":520,"wires":[["3b6cc1d6fe4fba16"]]},{"id":"7a9981e248c78dad","type":"change","z":"617486c48a1f4814","name":"append object key","rules":[{"t":"set","p":"path","pt":"msg","to":"$append(path, [parts.key])","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":410,"y":200,"wires":[["3495267e5776acbb"]]},{"id":"3495267e5776acbb","type":"switch","z":"617486c48a1f4814","name":"Am i an object?","property":"payload","propertyType":"msg","rules":[{"t":"istype","v":"object","vt":"object"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":620,"y":200,"wires":[["411cefe6a6bfce8f"],["75ab940ce6280d1d"]]},{"id":"be0147eea9d2b184","type":"link in","z":"617486c48a1f4814","name":"link in 11","links":[],"x":75,"y":200,"wires":[["7afccf9e887d2f3f"]]},{"id":"20d6dab3f38d10ef","type":"link out","z":"617486c48a1f4814","name":"link out 21","mode":"return","links":[],"x":1255,"y":340,"wires":[]},{"id":"3b6cc1d6fe4fba16","type":"link call","z":"617486c48a1f4814","name":"","links":["be0147eea9d2b184"],"linkType":"static","timeout":"30","x":700,"y":520,"wires":[["a52f1643606c0c35"]]},{"id":"75ab940ce6280d1d","type":"switch","z":"617486c48a1f4814","name":"Maybe an array?","property":"payload","propertyType":"msg","rules":[{"t":"istype","v":"array","vt":"array"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":770,"y":280,"wires":[["800e9c58dca07164"],["fc32f9a94be15162"]]},{"id":"800e9c58dca07164","type":"split","z":"617486c48a1f4814","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","property":"payload","x":890,"y":140,"wires":[["6cb69b4233c16619"]]},{"id":"6cb69b4233c16619","type":"change","z":"617486c48a1f4814","name":"append array index","rules":[{"t":"set","p":"path","pt":"msg","to":"$append(path,$string(parts.index))","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":1070,"y":140,"wires":[["ede929ded8464fbb"]]},{"id":"fc32f9a94be15162","type":"change","z":"617486c48a1f4814","name":"Join the path","rules":[{"t":"set","p":"path","pt":"msg","to":"$join(path,\".\")","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":990,"y":320,"wires":[["20d6dab3f38d10ef"]]},{"id":"daece5c19b59e289","type":"comment","z":"617486c48a1f4814","name":"ready?","info":"","x":870,"y":360,"wires":[]},{"id":"ede929ded8464fbb","type":"link out","z":"617486c48a1f4814","name":"link out 22","mode":"link","links":["d94d90b96e6c2add"],"x":1235,"y":140,"wires":[]},{"id":"d94d90b96e6c2add","type":"link in","z":"617486c48a1f4814","name":"link in 12","links":["ede929ded8464fbb"],"x":165,"y":80,"wires":[["7afccf9e887d2f3f"]]},{"id":"411cefe6a6bfce8f","type":"link out","z":"617486c48a1f4814","name":"link out 23","mode":"link","links":["eb2562651c2a031b"],"x":685,"y":80,"wires":[]},{"id":"eb2562651c2a031b","type":"link in","z":"617486c48a1f4814","name":"link in 13","links":["411cefe6a6bfce8f"],"x":165,"y":120,"wires":[["7afccf9e887d2f3f"]]},{"id":"16e9307dcb123549","type":"comment","z":"617486c48a1f4814","name":"out","info":"","x":1230,"y":380,"wires":[]},{"id":"a52f1643606c0c35","type":"join","z":"617486c48a1f4814","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"path","joiner":"\\n","joinerType":"str","useparts":false,"accumulate":false,"timeout":"0.1","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"num","reduceFixup":"","x":870,"y":520,"wires":[["95fdd7f5981bc3b8"]]}]

Thank you all for replying. When I ran JBudd's function I realized what was happening and that was not my intent. I am trying to get to a point where I have functions I can reuse and I think the getAllKeyValuePairs function will do the trick. At the end of the day I envision being able to run a json object into the function, then feed that into the UI template to auto populate the data. I can load the function in global context and just assign a const value to the context then call it when I need it in my flows. I think E1cid's object rewrite is what I can use for the global function.

Once again thanks

@E1cid solution is a great example of recursion however it will crash with a stack overflow if there are circular refs in the object pass to it.

If you are certain there will never be any circular refs in your data - forget I mentioned it.

If you do need to handle this, then it is pretty easy to handle (e.g. use a Set to keep track of visited paths & provide a quick escape)

2 Likes

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