Ich habe JSON wie folgt aus:JQ wählen dynamische Elemente aus json
{
"photo_807": "Ih2RnaBTg2o.jpg",
"photo_604": "zodCm9fQgX8.jpg",
"photo_130": "4Dx-SUNKBw4.jpg",
"photo_75": "7COWb8ou1qA.jpg",
"user_id": 100,
"owner_id": -2435432542783750,
"access_key": "fc5275423676514042234324265cc3df7607c",
"post_id": 380435645368865101,
"date": 14858616848616779856424245814,
"text": "",
"height": 417,
"width": 740,
"id": 45624575446886886564368555,
"album_id": -36
}
ich nur Foto-Werte erhalten wollen, von dem Ausgang möchte ich diese:
"photo_807": "Ih2RnaBTg2o.jpg"
"photo_604": "zodCm9fQgX8.jpg"
"photo_130": "4Dx-SUNKBw4.jpg"
Jetzt über mein Problem, von nächste JSON-Datei wird i foto~~POS=TRUNC mit neuen Namen wie diese:
"photo_181": "Ih2RnaBTg2o.jpg",
"photo_583": "zodCm9fQgX8.jpg",
"photo_975": "4Dx-SUNKBw4.jpg",
"photo_32": "7COWb8ou1qA.jpg",
, wie ich diese Werte von den dynamischen Posten bekommen foto_ *?
Ich versuche, so etwas wie dieses:
cat ./json3.txt | jq '.response.items[].attachments[].photo | select(.photo | startswith("photo"))'
Aber es funktioniert nicht.
Wenn ich laufen:
cat ./json3.txt | jq '.response.items[].attachments[].photo'
ich mit allen Elementen diese Ausgabe bekommen:
{
"photo_807": "Ih2RnaBTg2o.jpg",
"photo_604": "zodCm9fQgX8.jpg",
"photo_130": "4Dx-SUNKBw4.jpg",
"photo_75": "7COWb8ou1qA.jpg",
"user_id": 100,
"owner_id": -2435432542783750,
"access_key": "fc5275423676514042234324265cc3df7607c",
"post_id": 380435645368865101,
"date": 14858616848616779856424245814,
"text": "",
"height": 417,
"width": 740,
"id": 45624575446886886564368555,
"album_id": -36
}
Kann mir jemand helfen?
Vielen Dank im Voraus!
Jetzt mache ich es mit grep und schrecklichen sed-Kombinationen: cat ./json3.txt | jq '.response.items []. Anhänge []. photo' | grep "Foto_" | sed 's/"//' | sed 's /": //' | sed 's/", //' | sed 's /" //' Vielleicht kann jemand es nur mit jq machen? – Darkwind
Stellen Sie Ihre komplette 'JSON' aus Wurzel – Inian