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
- 2K Ideas Exchange
- Connect
- 1.3K Connectors
- 308 Workbench
- 7 Cloud Amplifier
- 10 Federated
- Transform
- 661 Datasets
- 117 SQL DataFlows
- 2.2K Magic ETL
- 819 Beast Mode
- Visualize
- 2.6K Charting
- 85 App Studio
- 46 Variables
- Automate
- 193 Apps
- 483 APIs & Domo Developer
- 85 Workflows
- 23 Code Engine
- AI and Machine Learning
- 22 AI Chat
- 3 AI Projects and Models
- 18 Jupyter Workspaces
- Distribute
- 116 Domo Everywhere
- 282 Scheduled Reports
- 11 Software Integrations
- Manage
- 142 Governance & Security
- 9 Domo Community Gallery
- 49 Product Releases
- 13 Domo University
- Community Forums
- 41 Getting Started
- 31 Community Member Introductions
- 115 Community Announcements
- 5K Archive