如何在雪花或JavaScript上动态地嵌套JSON?
这是我正在使用的JSON文件的一个示例,它具有大约600行相同的嵌套JSON结构。
{
"at": {
"Availability": "Yes",
"Message": "NV",
"Delivery option": "fast",
},
"childNodeIds": [],
"crawlMessageFlags": null,
"pd": {
"product_id": "product_id value",
"product_name": "product_name value",
"retailerName": "retailerName value",
"stock_status": "InStock",
"subClassName": "n/a"
},
"sellers": [],
"zipDetails": {}
}
我想生成一个报告,该报告将PD中的密钥作为列名称。 例如,
--------------------------------------------------------
product_id | product_name | retailerName
-----------------------------------------------------------
productid value1| product_name value1| retailerName value1
productid value2| product_name value2| retailerName value2
productid value3| product_name value3| retailerName value3
productid value4| product_name value4| retailerName value4
我可以用硬编码值生成此表,但是我想动态地进行此表,因为我们有几个不同的用例。
我尝试了网络上的几种解决方案,但是没有任何硬编码可以解决此问题。
有解决方案吗?
This is an example of the JSON file I'm working with, it has around 600 rows of the same nested JSON structure.
{
"at": {
"Availability": "Yes",
"Message": "NV",
"Delivery option": "fast",
},
"childNodeIds": [],
"crawlMessageFlags": null,
"pd": {
"product_id": "product_id value",
"product_name": "product_name value",
"retailerName": "retailerName value",
"stock_status": "InStock",
"subClassName": "n/a"
},
"sellers": [],
"zipDetails": {}
}
I want to generate a report that has the keys inside PD as the column names.
Example
--------------------------------------------------------
product_id | product_name | retailerName
-----------------------------------------------------------
productid value1| product_name value1| retailerName value1
productid value2| product_name value2| retailerName value2
productid value3| product_name value3| retailerName value3
productid value4| product_name value4| retailerName value4
I can generate this table with hardcoded values but I want to do it dynamically as we have several different use cases.
I have tried several solutions from the web but none solves this without hardcoding.
Any solutions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一种可能对您有用的方法。根据所得变量(输出)的结构,您可能需要相应地重构。
Here's one approach that might work for you. Depending on the structure of the resulting variable (output) you might want to refactor accordingly.