Parse data with no String name

SimonKing_Atolls
Member
in Connectors
I am building a new connector and some of the JSON data has no string names i.e.
{"user1":["PC1"],"user2":["PC4","PC5"],"user3":["PC1","PC2"]…..
If I use magicparse I just get 2 (very long) rows, where I'm after a column of names and a column of where they are seen.
is it possible to reference the data in another way such as
for(var i = 0; i < data.length; i++){
datagrid.addCell(data[i].[1])
datagrid.addCell(data[i].[2])
…..
Tagged:
0
Best Answer
-
You'll need two loops, one for each user and one for each pc:
jsonData = {"user1":["PC1"],"user2":["PC4","PC5"],"user3":["PC1","PC2"]} datagrid.addColumn('User',datagrid.DATA_TYPE_STRING) datagrid.addColumn('PC',datagrid.DATA_TYPE_STRING) for (var user in jsonData) { if (jsonData.hasOwnProperty(user)) { DOMO.log("User: " + user); var pcs = jsonData[user]; for (var i = 0; i < pcs.length; i++) { DOMO.log(" PC: " + pcs[i]); datagrid.addCell(user); datagrid.addCell(pcs[i]); datagrid.endRow(); } } }
0
Answers
-
You'll need two loops, one for each user and one for each pc:
jsonData = {"user1":["PC1"],"user2":["PC4","PC5"],"user3":["PC1","PC2"]} datagrid.addColumn('User',datagrid.DATA_TYPE_STRING) datagrid.addColumn('PC',datagrid.DATA_TYPE_STRING) for (var user in jsonData) { if (jsonData.hasOwnProperty(user)) { DOMO.log("User: " + user); var pcs = jsonData[user]; for (var i = 0; i < pcs.length; i++) { DOMO.log(" PC: " + pcs[i]); datagrid.addCell(user); datagrid.addCell(pcs[i]); datagrid.endRow(); } } }
0 -
This is brilliant, many thanks :)
0
Categories
- All Categories
- 2K Product Ideas
- 2K Ideas Exchange
- 1.6K Connect
- 1.3K Connectors
- 311 Workbench
- 6 Cloud Amplifier
- 9 Federated
- 3.8K Transform
- 657 Datasets
- 115 SQL DataFlows
- 2.2K Magic ETL
- 815 Beast Mode
- 3.3K Visualize
- 2.5K Charting
- 81 App Studio
- 45 Variables
- 775 Automate
- 190 Apps
- 481 APIs & Domo Developer
- 81 Workflows
- 23 Code Engine
- 40 AI and Machine Learning
- 20 AI Chat
- 1 AI Playground
- 1 AI Projects and Models
- 18 Jupyter Workspaces
- 410 Distribute
- 120 Domo Everywhere
- 280 Scheduled Reports
- 10 Software Integrations
- 144 Manage
- 140 Governance & Security
- 8 Domo Community Gallery
- 48 Product Releases
- 12 Domo University
- 5.4K Community Forums
- 41 Getting Started
- 31 Community Member Introductions
- 114 Community Announcements
- 4.8K Archive