Skip to content

Flatten

nntrn edited this page Sep 29, 2023 · 3 revisions

Flatten

jq '[leaf_paths as $path | {"key": $path | join("_"), "value": getpath($path)}] | from_entries'

Before

{
  "animal_id": "A878853",
  "location": {
    "latitude": "30.30666",
    "longitude": "-97.68963",
    "human_address": "{\"address\": \"5408 ABC DRIVE\", \"city\": \"AUSTIN\", \"state\": \"\", \"zip\": \"78723\"}"
  },
  "at_aac": "Yes (come to the shelter)",
  "intake_date": "2023-04-18T00:00:00.000",
  "type": "Dog",
  "looks_like": "Pit Bull Mix",
  "color": "Blue/White",
  "sex": "Intact Female",
  "age": "7 months",
  "image": {
    "url": "http://www.petharbor.com/pet.asp?uaid=ASTN.A878853"
  },
  ":@computed_region_8spj_utxs": "4",
  ":@computed_region_q9nd_rr82": "9",
  ":@computed_region_e9j2_6w3z": "84",
  ":@computed_region_m2th_e4b7": "309",
  ":@computed_region_rxpj_nzrk": "33",
  ":@computed_region_a3it_2a2z": "3239",
  ":@computed_region_hnvk_vq9u": "38"
}

After

{
  "animal_id": "A878853",
  "location_latitude": "30.30666",
  "location_longitude": "-97.68963",
  "location_human_address": "{\"address\": \"5408 ABC DRIVE\", \"city\": \"AUSTIN\", \"state\": \"\", \"zip\": \"78723\"}",
  "at_aac": "Yes (come to the shelter)",
  "intake_date": "2023-04-18T00:00:00.000",
  "type": "Dog",
  "looks_like": "Pit Bull Mix",
  "color": "Blue/White",
  "sex": "Intact Female",
  "age": "7 months",
  "image_url": "http://www.petharbor.com/pet.asp?uaid=ASTN.A878853",
  ":@computed_region_8spj_utxs": "4",
  ":@computed_region_q9nd_rr82": "9",
  ":@computed_region_e9j2_6w3z": "84",
  ":@computed_region_m2th_e4b7": "309",
  ":@computed_region_rxpj_nzrk": "33",
  ":@computed_region_a3it_2a2z": "3239",
  ":@computed_region_hnvk_vq9u": "38"
}
Clone this wiki locally