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
- Product Ideas
- 2.1K Ideas Exchange
- Connect
- 1.3K Connectors
- 309 Workbench
- 7 Cloud Amplifier
- 10 Federated
- Transform
- 664 Datasets
- 120 SQL DataFlows
- 2.3K Magic ETL
- 825 Beast Mode
- Visualize
- 2.6K Charting
- 88 App Studio
- 46 Variables
- Automate
- 196 Apps
- 486 APIs & Domo Developer
- 94 Workflows
- 24 Code Engine
- AI and Machine Learning
- 23 AI Chat
- 4 AI Projects and Models
- 18 Jupyter Workspaces
- Distribute
- 119 Domo Everywhere
- 283 Scheduled Reports
- 11 Software Integrations
- Manage
- 143 Governance & Security
- 11 Domo Community Gallery
- 49 Product Releases
- 13 Domo University
- Community Forums
- 41 Getting Started
- 31 Community Member Introductions
- 116 Community Announcements
- 5K Archive