How process JSON data that needs to be unpivoted?

核能气质少年 提交于 2020-01-05 04:55:57

问题


I have a JSON source that has a weird layout where there are unknown amount of columns.

https://theunitedstates.io/congress-legislators/committee-membership-current.json

The format is like the following:

ColumnHeaders =>    HLAG     HSAG    HSAG01 .... to unknown
Single row of Data  JSON     JSON    JSON

How can I get the data like this:

Col1     Col2
HLAG     JSON
HSAG     JSON
HSAG01   JSON

I am currently working in SSIS so I have C# solutions available to me.

I just don't know how to deal with unknown columns in SSIS.

Thanks for your help.


回答1:


In case you cannot find a more convenient solution, here's how it could be done using the command-line tool, jq:

jq -jrc 'keys_unsorted[] as $key | $key,"\t",.[$key],"\n" ' committee-membership-current.json

This produces one line per "column-header" in accordance with the problem description, using a literal tab ("\t") as separator. A different separator can be specified in the obvious manner.




回答2:


There are many articles online describing the process of parsing complex Json, the main idea is to use a script component with System.Web.Extensions assembly. I think that the following article is what you are looking for:

  • Importing Complex JSON files using SQL Server Integration Services

Other helpful articles:

  • Approaches to Import JSON in SSIS (SQL Server 2016+) Part 1
  • Importing JSON Files Using SQL Server Integration Services


来源:https://stackoverflow.com/questions/56534451/how-process-json-data-that-needs-to-be-unpivoted

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!