英文:
MLR tool to convert JSON to CSV and pad missing fields from all possible headers in json
问题
If I have three json objects in : test.json
{
"queue": "A",
"field1": 22,
"field2": 2,
"unique_field": 0
}
{
"queue": "B",
"field1": 39,
"field2": 3
}
{
"queue": "C",
"field1": 336,
"field2": 5
}
Running MLR to convert to CSV returns two unique sets based on headers
./mlr --j2c cat test.json
queue,field1,field2,unique_field
A,22,2,0
queue,field1,field2
B,39,3
C,336,5
What I would like is for MLR to pad any missing fields with null so only 1 header is present
queue,field1,field2,unique_field
A,22,2,0
B,39,3,null
C,336,5,null
I am not sure what to try yet, as need expertise from MLR community
英文:
If I have three json objects in : test.json
{
"queue": "A",
"field1": 22,
"field2": 2,
"unique_field": 0
}
{
"queue": "B",
"field1": 39,
"field2": 3
}
{
"queue": "C",
"field1": 336,
"field2": 5
}
Running MLR to convert to CSV returns two unique sets based on headers
./mlr --j2c cat test.json
queue,field1,field2,unique_field
A,22,2,0
queue,field1,field2
B,39,3
C,336,5
What I would like is for MLR to pad any missing fields with null so only 1 header is present
queue,field1,field2,unique_field
A,22,2,0
B,39,3,null
C,336,5,null
I am not sure what to try yet, as need expertise from MLR community
答案1
得分: 2
你必须使用 unsparsify 动词:
./mlr --j2c unsparsify test.json
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论