简体   繁体   中英

flatten keyless json to csv format using jq

How can I flatten the following json into csv format? The problem I am facing is that this json contains values in places of keys, and all the examples and tutorials that I have seen show how to handle json with keys and values. So I am not even sure where to begin.

JSON: This is what I currently have

{
  "AE": {
    "424,2": "Etisalat",
    "424,3": "DU"
  },
  "AF": {
    "412,50": "Etisalat"
  }
}

CSV: This is what I would like to have as output

"AE","424,2","Etisalat"
"AE","424,3","DU"
"AF","412,50","Etisalat"
paths(scalars) as $p | $p + [getpath($p)] | @csv

paths(scalars) finds paths to non-iterable values and lists them as arrays (eg ["AE","424,4"] ),
getpath($p) returns the value at path represented by $p .

Note that -r/--raw-output option is required for proper CSV output.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM