MLR工具将JSON转换为CSV,并从JSON的所有可能标题中填充丢失的字段

huangapple go评论55阅读模式
英文:

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
英文:

You must use the unsparsify verb:

./mlr --j2c unsparsify test.json

huangapple
  • 本文由 发表于 2023年4月7日 04:09:11
  • 转载请务必保留本文链接:https://go.coder-hub.com/75953380.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定