Здесь вы go
jq --compact-output '.report.clients[] | [.id, .name] + ((.books[] | ["books", .sku, .description]), (.movies[] | ["movie", .sku, .description]), (.dvds[] | ["dvds", .sku, .description]))'
["001","client_1","books","100","book title: book-A"]
["001","client_1","books","101","book title: book-B"]
["001","client_1","books","102","book title: book-C"]
["001","client_1","movie","200","movie title: movie-A"]
["001","client_1","movie","201","movie title: movie-B"]
["001","client_1","dvds","300","dvd title: dvd-A"]
["002","client_2","books","100","book title: book-A"]
["002","client_2","books","101","book title: book-B"]
["002","client_2","books","102","book title: book-C"]
["002","client_2","books","103","book title: book-D"]
["002","client_2","books","104","book title: book-E"]
["002","client_2","movie","200","movie title: movie-A"]
["002","client_2","dvds","300","dvd title: dvd-A"]
["002","client_2","dvds","301","dvd title: dvd-B"]
["002","client_2","dvds","302","dvd title: dvd-C"]
["002","client_2","dvds","303","dvd title: dvd-D"]
Попробуйте онлайн!
Если вы хотите истинный CSV, вы можете добавить | @csv
в конце
jq --compact-output '.report.clients[] | [.id, .name] + ((.books[] | ["books", .sku, .description]), (.movies[] | ["movie", .sku, .description]), (.dvds[] | ["dvds", .sku, .description])) | @csv'
"\"001\",\"client_1\",\"books\",\"100\",\"book title: book-A\""
"\"001\",\"client_1\",\"books\",\"101\",\"book title: book-B\""
"\"001\",\"client_1\",\"books\",\"102\",\"book title: book-C\""
"\"001\",\"client_1\",\"movie\",\"200\",\"movie title: movie-A\""
"\"001\",\"client_1\",\"movie\",\"201\",\"movie title: movie-B\""
"\"001\",\"client_1\",\"dvds\",\"300\",\"dvd title: dvd-A\""
"\"002\",\"client_2\",\"books\",\"100\",\"book title: book-A\""
"\"002\",\"client_2\",\"books\",\"101\",\"book title: book-B\""
"\"002\",\"client_2\",\"books\",\"102\",\"book title: book-C\""
"\"002\",\"client_2\",\"books\",\"103\",\"book title: book-D\""
"\"002\",\"client_2\",\"books\",\"104\",\"book title: book-E\""
"\"002\",\"client_2\",\"movie\",\"200\",\"movie title: movie-A\""
"\"002\",\"client_2\",\"dvds\",\"300\",\"dvd title: dvd-A\""
"\"002\",\"client_2\",\"dvds\",\"301\",\"dvd title: dvd-B\""
"\"002\",\"client_2\",\"dvds\",\"302\",\"dvd title: dvd-C\""
"\"002\",\"client_2\",\"dvds\",\"303\",\"dvd title: dvd-D\""
Попробуйте онлайн!
Если вы хотите что-то CSV-i sh, но не настоящий CSV, взгляните на join
. Например,
jq --compact-output --raw-output '.report.clients[] | [.id, .name] + ((.books[] | ["books", .sku, .description]), (.movies[] | ["movie", .sku, .description]), (.dvds[] | ["dvds", .sku, .description])) | join("|")'
001|client_1|books|100|book title: book-A
001|client_1|books|101|book title: book-B
001|client_1|books|102|book title: book-C
001|client_1|movie|200|movie title: movie-A
001|client_1|movie|201|movie title: movie-B
001|client_1|dvds|300|dvd title: dvd-A
002|client_2|books|100|book title: book-A
002|client_2|books|101|book title: book-B
002|client_2|books|102|book title: book-C
002|client_2|books|103|book title: book-D
002|client_2|books|104|book title: book-E
002|client_2|movie|200|movie title: movie-A
002|client_2|dvds|300|dvd title: dvd-A
002|client_2|dvds|301|dvd title: dvd-B
002|client_2|dvds|302|dvd title: dvd-C
002|client_2|dvds|303|dvd title: dvd-D
Попробуйте онлайн!
Дайте мне знать, если у вас есть какие-либо вопросы. Надеюсь, это поможет!