私はここまでたどり着くことができました。
json 入力、「data.json」:
[
{
"Selected": null,
"Family Name": "Jones",
"Couple Name": "Jones, Adam & Rachael Margaret",
"Family Phone": "404-4477",
"Family Email": "email@sbcglobal.net",
"Family Address": "777 Aggies Court Kindly, California 95388 ",
"Head Of House Name": "Jones, Adam",
"Head Of House Phone": "(583) 404-2488",
"Head Of House Email": "email@sbcglobal.net",
"Spouse Name": "Jones, Rachael Margaret",
"Spouse Phone": null,
"Spouse Email": null,
"Child Name": null,
"Child Phone": null,
"Child Email": null
},
{
"Selected": "x",
"Family Name": "Xiong",
"Couple Name": "Xiong, Arlene Frances",
"Family Phone": null,
"Family Email": null,
"Family Address": "888 Walnut Ave. Blatant, California 95388 ",
"Head Of House Name": "Xiong, Arlene Frances",
"Head Of House Phone": "583-500-7917",
"Head Of House Email": "email@junk.net",
"Spouse Name": null,
"Spouse Phone": null,
"Spouse Email": null,
"Child Name": null,
"Child Phone": null,
"Child Email": null
},
{
"Selected": "x",
"Family Name": "Blair",
"Couple Name": "Blair, Toby & Silvia",
"Family Phone": "358-4645",
"Family Email": null,
"Family Address": "333 Cindy St. Stoic, California 95388 ",
"Head Of House Name": "Blair, Toby",
"Head Of House Phone": null,
"Head Of House Email": "email@stuff.net",
"Spouse Name": "Blair, Silvia",
"Spouse Phone": null,
"Spouse Email": null,
"Child Name": null,
"Child Phone": null,
"Child Email": null
}
]
これを使用してフィルタリングできます。
cat data.json | jq '.[] | select(.Selected != null) | {"Head Of House Name", "Head Of House Phone", "Head Of House Email", "Family Phone", "Family Email"}'
結果:
{
"Head Of House Name": "Xiong, Arlene Frances",
"Head Of House Phone": "583-500-7917",
"Head Of House Email": "email@junk.net",
"Family Phone": null,
"Family Email": null
}
{
"Head Of House Name": "Blair, Toby",
"Head Of House Phone": null,
"Head Of House Email": "email@stuff.net",
"Family Phone": "358-4645",
"Family Email": null
}
オブジェクトの配列の周りに配列ブラケットがなく、オブジェクト間にコンマがないことに注意してください...結果が配列ではないことを示しています。
問題は、結果がオブジェクトの配列ではないことです (率直に言って、それが何であるかはわかりません)。json オブジェクトの配列から始めて、それらをフィルタリングし、フィルタリングされたオブジェクトのリストで終わるにはどうすればよいですか?