Datasets:
File size: 57,987 Bytes
837bf81 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | {"id":"so-18592173","request":"From a JSON object where values are objects containing 'name' and 'location', select only those objects where 'location' is 'Stockholm' and output their 'name' values.","command":"jq -r '.[] | select(.location == \"Stockholm\") | .name'","input_text":"{\"FOO\": {\"name\": \"Donald\", \"location\": \"Stockholm\"}, \"BAR\": {\"name\": \"Walt\", \"location\": \"Stockholm\"}, \"BAZ\": {\"name\": \"Jack\", \"location\": \"Whereever\"}}","expected_output":"Donald\nWalt\n","validation_input":"{\"A\": {\"name\": \"Alice\", \"location\": \"Stockholm\"}, \"B\": {\"name\": \"Bob\", \"location\": \"London\"}}","validation_output":"Alice\n","family":"real-stackoverflow","difficulty":3,"split":"test","source":"stackoverflow-accepted-answer","license":"CC-BY-SA-4.0","question_url":"https://stackoverflow.com/questions/18592173/select-objects-based-on-value-of-variable-in-object-using-jq","question_title":"Select objects based on value of variable in object using jq","question_owner":"Daniel","answer_owner":"Daniel","answer_id":18608100,"question_score":557,"reviewed":true}
{"id":"so-1955505","request":"Extract the value of the 'text' field from a JSON object.","command":"jq -r '.text'","input_text":"{\"text\": \"My status\", \"favorited\": false}","expected_output":"My status\n","validation_input":"{\"text\": \"Another update\", \"favorited\": true}","validation_output":"Another update\n","family":"real-stackoverflow","difficulty":3,"split":"test","source":"stackoverflow-accepted-answer","license":"CC-BY-SA-4.0","question_url":"https://stackoverflow.com/questions/1955505/parsing-json-with-unix-tools","question_title":"Parsing JSON with Unix tools","question_owner":"auser","answer_owner":"Brian Campbell","answer_id":1955555,"question_score":1322,"reviewed":true}
{"id":"so-19573517","request":"Select and output only the objects from the input stream where the 'geo' field is not null.","command":"jq 'select(.geo != null)'","input_text":"{\"geo\": {\"lat\": 1.0}}\n{\"geo\": null}\n{\"geo\": {\"lat\": 2.0}}","expected_output":"{\n \"geo\": {\n \"lat\": 1\n }\n}\n{\n \"geo\": {\n \"lat\": 2\n }\n}\n","validation_input":"{\"geo\": null}\n{\"geo\": {\"lng\": 5.0}}\n{\"geo\": null}","validation_output":"{\n \"geo\": {\n \"lng\": 5\n }\n}\n","family":"real-stackoverflow","difficulty":3,"split":"test","source":"stackoverflow-accepted-answer","license":"CC-BY-SA-4.0","question_url":"https://stackoverflow.com/questions/19573517/jq-conditional-output","question_title":"jq Conditional output","question_owner":"clwen","answer_owner":"max taldykin","answer_id":20489951,"question_score":120,"reviewed":true}
{"id":"so-20181467","request":"Convert a JSON object with dynamic keys into CSV format, where each line contains the key and value quoted and separated by a comma.","command":"jq -r 'to_entries[] | [.key, .value] | @csv'","input_text":"{\"123\":\"abc\",\"231\":\"dbh\",\"452\":\"xyz\"}","expected_output":"\"123\",\"abc\"\n\"231\",\"dbh\"\n\"452\",\"xyz\"\n","validation_input":"{\"a\":\"1\",\"b\":\"2\"}","validation_output":"\"a\",\"1\"\n\"b\",\"2\"\n","family":"real-stackoverflow","difficulty":3,"split":"test","source":"stackoverflow-accepted-answer","license":"CC-BY-SA-4.0","question_url":"https://stackoverflow.com/questions/20181467/how-to-map-an-object-to-arrays-so-it-can-be-converted-to-csv","question_title":"How to map an object to arrays so it can be converted to csv?","question_owner":"lsl","answer_owner":"Jeff Mercado","answer_id":24254365,"question_score":54,"reviewed":true}
{"id":"so-21334348","request":"Count the number of items in the top-level JSON array.","command":"jq length","input_text":"[\n {\n \"cid\": 49,\n \"pyn\": \"yi4\",\n \"hans\": \"亿\",\n \"hant\": \"億\",\n \"tid\": 68,\n \"l10n\": \"cent million\",\n \"pid\": 1,\n \"pos\": \"num\",\n \"pos_txt\": \"\"\n },\n {\n \"cid\": 50,\n \"pyn\": \"yi4\",\n \"hans\": \"亿\",\n \"hant\": \"億\",\n \"tid\": 69,\n \"l10n\": \"100 millions\",\n \"pid\": 1,\n \"pos\": \"num\",\n \"pos_txt\": \"\"\n }\n]","expected_output":"2\n","validation_input":"[\n {\n \"id\": 1\n },\n {\n \"id\": 2\n },\n {\n \"id\": 3\n }\n]","validation_output":"3\n","family":"real-stackoverflow","difficulty":3,"split":"test","source":"stackoverflow-accepted-answer","license":"CC-BY-SA-4.0","question_url":"https://stackoverflow.com/questions/21334348/how-to-count-items-in-json-object-using-command-line","question_title":"How to count items in JSON object using command line?","question_owner":"Édouard Lopez","answer_owner":"Ken","answer_id":21355442,"question_score":476,"reviewed":true}
{"id":"so-23118341","request":"Extract the keys from the JSON object as a sorted array of strings.","command":"jq keys","input_text":"{\n \"email\": \"madireddy@test.com\",\n \"versionID\": \"2323\",\n \"context\": \"test\",\n \"date\": \"02-03-2014-13:41\",\n \"versionName\": \"application\"\n}","expected_output":"[\n \"context\",\n \"date\",\n \"email\",\n \"versionID\",\n \"versionName\"\n]\n","validation_input":"{\n \"Created-By\": \"Apache Maven\",\n \"Build-Number\": \"\",\n \"Archiver-Version\": \"Plexus Archiver\"\n}","validation_output":"[\n \"Archiver-Version\",\n \"Build-Number\",\n \"Created-By\"\n]\n","family":"real-stackoverflow","difficulty":3,"split":"test","source":"stackoverflow-accepted-answer","license":"CC-BY-SA-4.0","question_url":"https://stackoverflow.com/questions/23118341/how-to-get-key-names-from-json-using-jq","question_title":"How to get key names from JSON using jq","question_owner":"Ezhilan Mahalingam","answer_owner":"anubhava","answer_id":23118607,"question_score":314,"reviewed":true}
{"id":"so-24698188","request":"Given a JSON array of objects, flatten each object by removing the 'fields' key and promoting its values (taking the first element if they are arrays) to the top level, while preserving other top-level keys.","command":"jq 'map(with_entries(select(.key != \"fields\")) + (.fields | with_entries(.value = .value[0])))'","input_text":"[\n {\n \"index\": \"index1\",\n \"type\": \"type1\",\n \"id\": \"id1\",\n \"fields\": {\n \"deviceOs\": [\"Android\"],\n \"deviceID\": [\"deviceID1\"],\n \"country\": [\"DE\"]\n }\n },\n {\n \"index\": \"index2\",\n \"type\": \"type2\",\n \"id\": \"id2\",\n \"fields\": {\n \"deviceOs\": [\"iOS\"],\n \"deviceID\": [\"deviceID2\"],\n \"country\": [\"US\"]\n }\n }\n]","expected_output":"[\n {\n \"index\": \"index1\",\n \"type\": \"type1\",\n \"id\": \"id1\",\n \"deviceOs\": \"Android\",\n \"deviceID\": \"deviceID1\",\n \"country\": \"DE\"\n },\n {\n \"index\": \"index2\",\n \"type\": \"type2\",\n \"id\": \"id2\",\n \"deviceOs\": \"iOS\",\n \"deviceID\": \"deviceID2\",\n \"country\": \"US\"\n }\n]\n","validation_input":"[\n {\n \"index\": \"idx1\",\n \"val\": \"v1\",\n \"fields\": {\n \"a\": [\"x\"],\n \"b\": [\"y\"]\n }\n }\n]","validation_output":"[\n {\n \"index\": \"idx1\",\n \"val\": \"v1\",\n \"a\": \"x\",\n \"b\": \"y\"\n }\n]\n","family":"real-stackoverflow","difficulty":3,"split":"test","source":"stackoverflow-accepted-answer","license":"CC-BY-SA-4.0","question_url":"https://stackoverflow.com/questions/24698188/flatten-a-json-document-using-jq","question_title":"Flatten a JSON document using jq","question_owner":"Dror","answer_owner":"Jeff Mercado","answer_id":24710337,"question_score":39,"reviewed":true}
{"id":"so-25378013","request":"Convert a JSON object into a list of strings where each string is formatted as \"key=value\".","command":"jq -r 'to_entries|map(\"\\(.key)=\\(.value|tostring)\")|.[]'","input_text":"{\n \"var\": 1,\n \"foo\": \"bar\",\n \"x\": \"test\"\n}","expected_output":"var=1\nfoo=bar\nx=test\n","validation_input":"{\n \"name\": \"Alice\",\n \"age\": 30,\n \"active\": true\n}","validation_output":"name=Alice\nage=30\nactive=true\n","family":"real-stackoverflow","difficulty":3,"split":"test","source":"stackoverflow-accepted-answer","license":"CC-BY-SA-4.0","question_url":"https://stackoverflow.com/questions/25378013/how-to-convert-a-json-object-to-key-value-format-in-jq","question_title":"How to convert a JSON object to key=value format in jq?","question_owner":"gianebao","answer_owner":"aioobe","answer_id":25378171,"question_score":75,"reviewed":true}
{"id":"so-26701538","request":"From a JSON array of objects each having an 'Id' string and a 'Names' array of strings, filter out any object where any name in 'Names' contains the substring 'data', and output the 'Id' of the remaining objects.","command":"jq -r '.[] | select(.Names | all(contains(\"data\") | not)) | .Id'","input_text":"[{\"Id\": \"abc\", \"Names\": [\"condescending_jones\"]}, {\"Id\": \"def\", \"Names\": [\"foo_data\"]}]","expected_output":"abc\n","validation_input":"[{\"Id\": \"123\", \"Names\": [\"jovial_wozniak\"]}, {\"Id\": \"456\", \"Names\": [\"bar_data\"]}, {\"Id\": \"mix\", \"Names\": [\"foo_data\", \"safe\"]}]","validation_output":"123\n","family":"real-stackoverflow","difficulty":3,"split":"test","source":"stackoverflow-accepted-answer","license":"CC-BY-SA-4.0","question_url":"https://stackoverflow.com/questions/26701538/jq-how-to-filter-an-array-of-objects-based-on-values-in-an-inner-array","question_title":"jq: how to filter an array of objects based on values in an inner array?","question_owner":"Abe Voelker","answer_owner":"Iain Samuel McLean Elder","answer_id":26701851,"question_score":518,"reviewed":true}
{"id":"so-27562424","request":"For each object in the input array, create a new object containing the top-level id and the value of info-spec from the nested stuff object.","command":"jq '[.[] | {id, \"info-spec\": .stuff[\"info-spec\"]}]'","input_text":"[{\"id\": 12345678, \"stuff\": {\"book\": \"shelf\", \"hook\": \"line\", \"took\": \"off\", \"info-spec\": 12}, \"votes\": 23}, {\"id\": 12345679, \"stuff\": {\"book\": \"maker\", \"hook\": \"sinker\", \"took\": \"pisin\", \"info-spec\": 23}, \"votes\": 1}]","expected_output":"[\n {\n \"id\": 12345678,\n \"info-spec\": 12\n },\n {\n \"id\": 12345679,\n \"info-spec\": 23\n }\n]\n","validation_input":"[{\"id\": 999, \"stuff\": {\"info-spec\": 100, \"other\": \"val\"}}, {\"id\": 888, \"stuff\": {\"info-spec\": 200, \"other\": \"val2\"}}]","validation_output":"[\n {\n \"id\": 999,\n \"info-spec\": 100\n },\n {\n \"id\": 888,\n \"info-spec\": 200\n }\n]\n","family":"real-stackoverflow","difficulty":3,"split":"test","source":"stackoverflow-accepted-answer","license":"CC-BY-SA-4.0","question_url":"https://stackoverflow.com/questions/27562424/jq-nested-object-extract-top-level-id-and-lift-a-value-from-internal-object","question_title":"jq: nested object, extract top-level id and lift a value from internal object","question_owner":"tripleee","answer_owner":"tripleee","answer_id":27562901,"question_score":42,"reviewed":true}
{"id":"so-28484534","request":"Read a stream of JSON objects and output a single object where each key's value is the sum of that key's values across all input objects.","command":"jq -s '[.[] | to_entries] | add | group_by(.key) | map({key: .[0].key, value: map(.value) | add}) | from_entries'","input_text":"{ \"a\": 10, \"b\": 11 }\n{ \"a\": 20, \"b\": 21 }","expected_output":"{\n \"a\": 30,\n \"b\": 32\n}\n","validation_input":"{ \"x\": 5, \"y\": 10 }\n{ \"x\": 15, \"y\": 20 }\n{ \"x\": 0, \"y\": 5 }","validation_output":"{\n \"x\": 20,\n \"y\": 35\n}\n","family":"real-stackoverflow","difficulty":3,"split":"test","source":"stackoverflow-accepted-answer","license":"CC-BY-SA-4.0","question_url":"https://stackoverflow.com/questions/28484534/how-do-i-sum-the-values-in-an-array-of-maps-in-jq","question_title":"How do I sum the values in an array of maps in jq?","question_owner":"Alan Burlison","answer_owner":"Jeff Mercado","answer_id":28485485,"question_score":46,"reviewed":true}
{"id":"so-29404575","request":"Convert a stream of JSON objects into a single JSON array containing all the objects.","command":"jq -s '.'","input_text":"{\"a\":1}\n{\"b\":2}","expected_output":"[\n {\n \"a\": 1\n },\n {\n \"b\": 2\n }\n]\n","validation_input":"{\"x\":\"foo\"}\n{\"y\":\"bar\"}\n{\"z\":123}","validation_output":"[\n {\n \"x\": \"foo\"\n },\n {\n \"y\": \"bar\"\n },\n {\n \"z\": 123\n }\n]\n","family":"real-stackoverflow","difficulty":3,"split":"test","source":"stackoverflow-accepted-answer","license":"CC-BY-SA-4.0","question_url":"https://stackoverflow.com/questions/29404575/how-to-convert-a-json-object-stream-into-an-array-with-jq","question_title":"How to convert a JSON object stream into an array with jq","question_owner":"Qiang Li","answer_owner":"Jeff Mercado","answer_id":29404613,"question_score":46,"reviewed":true}
{"id":"so-29949184","request":"Filter a JSON object to keep only items with id \"123\" in the \"requests\" array if it exists and is non-empty, otherwise output nothing.","command":"jq 'if (.requests | length) != 0 then .requests |= map(select(.id == \"123\")) else empty end'","input_text":"{\"requests\":[{\"id\":\"123\"},{\"id\":\"456\"}]}","expected_output":"{\n \"requests\": [\n {\n \"id\": \"123\"\n }\n ]\n}\n","validation_input":"{\"requests\":[{\"id\":\"789\"}]}","validation_output":"{\n \"requests\": []\n}\n","family":"real-stackoverflow","difficulty":3,"split":"test","source":"stackoverflow-accepted-answer","license":"CC-BY-SA-4.0","question_url":"https://stackoverflow.com/questions/29949184/json-jq-if-without-else","question_title":"JSON JQ if without else","question_owner":"user1578872","answer_owner":"peak","answer_id":29962258,"question_score":53,"reviewed":true}
{"id":"so-31034746","request":"Set the value of the key \"local\" inside the \"shipping\" object to false, preserving the rest of the JSON structure.","command":"jq '.shipping.local = false'","input_text":"{\"shipping\": {\"local\": true, \"us\": true, \"us_rate\": {\"amount\": \"0.00\", \"currency\": \"USD\", \"symbol\": \"$\"}}}","expected_output":"{\n \"shipping\": {\n \"local\": false,\n \"us\": true,\n \"us_rate\": {\n \"amount\": \"0.00\",\n \"currency\": \"USD\",\n \"symbol\": \"$\"\n }\n }\n}\n","validation_input":"{\"shipping\": {\"local\": true, \"international\": false}, \"other\": \"data\"}","validation_output":"{\n \"shipping\": {\n \"local\": false,\n \"international\": false\n },\n \"other\": \"data\"\n}\n","family":"real-stackoverflow","difficulty":3,"split":"test","source":"stackoverflow-accepted-answer","license":"CC-BY-SA-4.0","question_url":"https://stackoverflow.com/questions/31034746/how-do-i-update-a-single-value-in-a-json-document-using-jq","question_title":"How do I update a single value in a json document using jq?","question_owner":"STW","answer_owner":"Jeff Mercado","answer_id":31037640,"question_score":231,"reviewed":true}
{"id":"so-33247228","request":"Pretty-print the input JSON using jq's default formatting.","command":"jq '.'","input_text":"{\"name\": \"octocat\", \"id\": 1}","expected_output":"{\n \"name\": \"octocat\",\n \"id\": 1\n}\n","validation_input":"{\"key\": \"value\", \"nested\": {\"a\": 1}}","validation_output":"{\n \"key\": \"value\",\n \"nested\": {\n \"a\": 1\n }\n}\n","family":"real-stackoverflow","difficulty":3,"split":"test","source":"stackoverflow-accepted-answer","license":"CC-BY-SA-4.0","question_url":"https://stackoverflow.com/questions/33247228/how-to-use-jq-in-a-shell-pipeline","question_title":"How to use `jq` in a shell pipeline?","question_owner":"mgalgs","answer_owner":"chepner","answer_id":33247259,"question_score":244,"reviewed":true}
{"id":"so-33895076","request":"Given a JSON array of objects containing 'timestamp', 'group', and 'uid' fields, output each object's 'group' and 'uid' values joined by a comma on separate lines.","command":"jq -r '.[]|[.group,.uid]|join(\",\")'","input_text":"[\n {\n \"timestamp\": 1448369447295,\n \"group\": \"employees\",\n \"uid\": \"elgalu\"\n },\n {\n \"timestamp\": 1448369447296,\n \"group\": \"employees\",\n \"uid\": \"mike\"\n },\n {\n \"timestamp\": 1448369786667,\n \"group\": \"services\",\n \"uid\": \"pacts\"\n }\n]","expected_output":"employees,elgalu\nemployees,mike\nservices,pacts\n","validation_input":"[\n {\n \"timestamp\": 100,\n \"group\": \"admin\",\n \"uid\": \"root\"\n },\n {\n \"timestamp\": 200,\n \"group\": \"users\",\n \"uid\": \"guest\"\n }\n]","validation_output":"admin,root\nusers,guest\n","family":"real-stackoverflow","difficulty":3,"split":"test","source":"stackoverflow-accepted-answer","license":"CC-BY-SA-4.0","question_url":"https://stackoverflow.com/questions/33895076/exclude-column-from-jq-json-output","question_title":"Exclude column from jq json output","question_owner":"Leo Gallucci","answer_owner":"hek2mgl","answer_id":33895231,"question_score":87,"reviewed":true}
{"id":"so-33947584","request":"Extract start_id and end_id from each JSON object and print them on the same line separated by a space, without surrounding double quotes.","command":"jq -r '\"\\(.start_id) \\(.end_id)\"'","input_text":"{\"start_id\":1,\"end_id\":50}\n{\"start_id\":50,\"end_id\":99}\n{\"start_id\":99,\"end_id\":12}","expected_output":"1 50\n50 99\n99 12\n","validation_input":"{\"start_id\":10,\"end_id\":20}\n{\"start_id\":20,\"end_id\":30}","validation_output":"10 20\n20 30\n","family":"real-stackoverflow","difficulty":3,"split":"test","source":"stackoverflow-accepted-answer","license":"CC-BY-SA-4.0","question_url":"https://stackoverflow.com/questions/33947584/concat-numbers-from-json-without-doublequotes-using-jq","question_title":"Concat numbers from JSON without doublequotes using jq","question_owner":"Synesso","answer_owner":"xjedam","answer_id":33952189,"question_score":39,"reviewed":true}
{"id":"so-34226370","request":"Given a JSON object where keys are hostnames and values are objects containing an 'ip' field, output each hostname and its corresponding IP address as a comma-separated string on separate lines.","command":"jq -r 'to_entries[] | \"\\(.key), \\(.value.ip)\"'","input_text":"{\n \"host1\": { \"ip\": \"10.1.2.3\" },\n \"host2\": { \"ip\": \"10.1.2.2\" },\n \"host3\": { \"ip\": \"10.1.18.1\" }\n}","expected_output":"host1, 10.1.2.3\nhost2, 10.1.2.2\nhost3, 10.1.18.1\n","validation_input":"{\n \"serverA\": { \"ip\": \"192.168.1.1\" },\n \"serverB\": { \"ip\": \"192.168.1.2\" }\n}","validation_output":"serverA, 192.168.1.1\nserverB, 192.168.1.2\n","family":"real-stackoverflow","difficulty":3,"split":"test","source":"stackoverflow-accepted-answer","license":"CC-BY-SA-4.0","question_url":"https://stackoverflow.com/questions/34226370/jq-print-key-and-value-for-each-entry-in-an-object","question_title":"jq: print key and value for each entry in an object","question_owner":"Jeff Tang","answer_owner":"peak","answer_id":34227629,"question_score":164,"reviewed":true}
{"id":"so-34340549","request":"Parse the JSON string contained in the \"text\" field of the \"response\" object and extract the \"title\" field from the parsed JSON.","command":"jq '.response.text | fromjson | .title'","input_text":"{\n \"requestType\": \"POST\",\n \"response\": {\n \"size\": 78,\n \"text\": \"{\\\"recordID\\\":123, \\\"title\\\":\\\"Hello World\\\", \\\"content\\\":\\\"Lorem ipsum...\\\"}\"\n }\n}","expected_output":"\"Hello World\"\n","validation_input":"{\n \"requestType\": \"GET\",\n \"response\": {\n \"size\": 50,\n \"text\": \"{\\\"id\\\":456, \\\"title\\\":\\\"Goodbye World\\\", \\\"data\\\":null}\"\n }\n}","validation_output":"\"Goodbye World\"\n","family":"real-stackoverflow","difficulty":3,"split":"test","source":"stackoverflow-accepted-answer","license":"CC-BY-SA-4.0","question_url":"https://stackoverflow.com/questions/34340549/convert-string-to-json-in-jq","question_title":"Convert string to json in jq","question_owner":"RJ-Adam","answer_owner":"Jeff Mercado","answer_id":34340787,"question_score":100,"reviewed":true}
{"id":"so-34543829","request":"Extract the 'def' value from the 'aux' array within each object of the top-level array.","command":"jq -r '.[].aux[].def'","input_text":"[{\"id\": 123, \"name\": \"John\", \"aux\": [{\"abc\": \"random\", \"def\": \"I want this\"}], \"blah\": 23.11}]","expected_output":"I want this\n","validation_input":"[{\"id\": 456, \"name\": \"Jane\", \"aux\": [{\"abc\": \"x\", \"def\": \"Target Value\"}], \"blah\": 10.0}]","validation_output":"Target Value\n","family":"real-stackoverflow","difficulty":3,"split":"test","source":"stackoverflow-accepted-answer","license":"CC-BY-SA-4.0","question_url":"https://stackoverflow.com/questions/34543829/jq-cannot-index-array-with-string","question_title":"jq: Cannot index array with string","question_owner":"Xu Wang","answer_owner":"hek2mgl","answer_id":34544406,"question_score":115,"reviewed":true}
{"id":"so-35086391","request":"Given a JSON object where values are objects with a single key, output all the inner keys as a stream of strings.","command":"jq '.[] | keys[]'","input_text":"{\n \"keyword1\": {\n \"identifier1\": 16\n },\n \"keyword2\": {\n \"identifier2\": 16\n }\n}","expected_output":"\"identifier1\"\n\"identifier2\"\n","validation_input":"{\n \"groupA\": {\n \"nameA\": 1\n },\n \"groupB\": {\n \"nameB\": 2\n }\n}","validation_output":"\"nameA\"\n\"nameB\"\n","family":"real-stackoverflow","difficulty":3,"split":"test","source":"stackoverflow-accepted-answer","license":"CC-BY-SA-4.0","question_url":"https://stackoverflow.com/questions/35086391/jq-how-to-iterate-through-keys-of-different-names","question_title":"jq - How to iterate through keys of different names","question_owner":"Adam vonNieda","answer_owner":"peak","answer_id":35091473,"question_score":40,"reviewed":true}
{"id":"so-35154684","request":"Parse the JSON string contained in the field \"c\" and extract the value of its \"id\" field.","command":"jq '.c | fromjson | .id'","input_text":"{\"a\": 1, \"b\": 2, \"c\": \"{\\\"id\\\":\\\"9ee\\\",\\\"parent\\\":\\\"abc\\\"}\"}","expected_output":"\"9ee\"\n","validation_input":"{\"x\": 10, \"c\": \"{\\\"id\\\":\\\"xyz123\\\",\\\"type\\\":\\\"user\\\"}\"}","validation_output":"\"xyz123\"\n","family":"real-stackoverflow","difficulty":3,"split":"test","source":"stackoverflow-accepted-answer","license":"CC-BY-SA-4.0","question_url":"https://stackoverflow.com/questions/35154684/how-to-parse-a-json-string-with-jq-or-other-alternatives","question_title":"how to parse a JSON String with jq (or other alternatives)?","question_owner":"Colin Grogan","answer_owner":"jwodder","answer_id":35155249,"question_score":217,"reviewed":true}
{"id":"so-35677309","request":"Extract the \"AssetId\" value from each object in a JSON array and output them as raw strings.","command":"jq -r '.[] | .AssetId'","input_text":"[\n {\n \"AssetId\": 14462955,\n \"Name\": \"Cultural Item\"\n },\n {\n \"AssetId\": 114385498,\n \"Name\": \"Redspybot\"\n },\n {\n \"AssetId\": 29715011,\n \"Name\": \"American Cowboy\"\n },\n {\n \"AssetId\": 98253651,\n \"Name\": \"Mahem\"\n }\n]","expected_output":"14462955\n114385498\n29715011\n98253651\n","validation_input":"[\n {\n \"AssetId\": 100,\n \"Name\": \"Item A\"\n },\n {\n \"AssetId\": 200,\n \"Name\": \"Item B\"\n }\n]","validation_output":"100\n200\n","family":"real-stackoverflow","difficulty":3,"split":"test","source":"stackoverflow-accepted-answer","license":"CC-BY-SA-4.0","question_url":"https://stackoverflow.com/questions/35677309/output-specific-key-value-in-object-for-each-element-in-array-with-jq-for-json","question_title":"Output specific key value in object for each element in array with jq for JSON","question_owner":"Zimbabwe Elephant","answer_owner":"peak","answer_id":35677443,"question_score":98,"reviewed":true}
{"id":"so-36227245","request":"Remove the keys \"Country\", \"number\", and \"Language\" from each object in a JSON array.","command":"jq 'map(del(.Country, .number, .Language))'","input_text":"[\n {\n \"label\": \"US : USA : English\",\n \"Country\": \"USA\",\n \"region\": \"US\",\n \"Language\": \"English\",\n \"locale\": \"en\",\n \"currency\": \"USD\",\n \"number\": \"USD\"\n },\n {\n \"label\": \"AU : Australia : English\",\n \"Country\": \"Australia\",\n \"region\": \"AU\",\n \"Language\": \"English\",\n \"locale\": \"en\",\n \"currency\": \"AUD\",\n \"number\": \"AUD\"\n }\n]","expected_output":"[\n {\n \"label\": \"US : USA : English\",\n \"region\": \"US\",\n \"locale\": \"en\",\n \"currency\": \"USD\"\n },\n {\n \"label\": \"AU : Australia : English\",\n \"region\": \"AU\",\n \"locale\": \"en\",\n \"currency\": \"AUD\"\n }\n]\n","validation_input":"[\n {\n \"label\": \"CA : Canada : English\",\n \"Country\": \"Canada\",\n \"region\": \"CA\",\n \"Language\": \"English\",\n \"locale\": \"en\",\n \"currency\": \"CAD\",\n \"number\": \"CAD\"\n },\n {\n \"label\": \"GB : UK : English\",\n \"Country\": \"UK\",\n \"region\": \"GB\",\n \"Language\": \"English\",\n \"locale\": \"en\",\n \"currency\": \"GBP\",\n \"number\": \"GBP\"\n }\n]","validation_output":"[\n {\n \"label\": \"CA : Canada : English\",\n \"region\": \"CA\",\n \"locale\": \"en\",\n \"currency\": \"CAD\"\n },\n {\n \"label\": \"GB : UK : English\",\n \"region\": \"GB\",\n \"locale\": \"en\",\n \"currency\": \"GBP\"\n }\n]\n","family":"real-stackoverflow","difficulty":3,"split":"test","source":"stackoverflow-accepted-answer","license":"CC-BY-SA-4.0","question_url":"https://stackoverflow.com/questions/36227245/deleting-multiple-keys-at-once-with-jq","question_title":"Deleting multiple keys at once with jq","question_owner":"antun","answer_owner":"user3899165","answer_id":36228054,"question_score":79,"reviewed":true}
{"id":"so-37344329","request":"Extract the value of the key \"component-status\" from a JSON object.","command":"jq '.\"component-status\"'","input_text":"{\n \"status\": \"ok\",\n \"hostname\": \"0b0b495a46db\",\n \"component-status\": [\n {\n \"status-code\": 200,\n \"component\": \"Service1\",\n \"status\": \"OK\"\n },\n {\n \"status-code\": 200,\n \"component\": \"Service2\",\n \"status\": \"OK\"\n }\n ]\n}","expected_output":"[\n {\n \"status-code\": 200,\n \"component\": \"Service1\",\n \"status\": \"OK\"\n },\n {\n \"status-code\": 200,\n \"component\": \"Service2\",\n \"status\": \"OK\"\n }\n]\n","validation_input":"{\n \"status\": \"error\",\n \"hostname\": \"test-host\",\n \"component-status\": [\n {\n \"status-code\": 500,\n \"component\": \"DB\",\n \"status\": \"FAIL\"\n }\n ]\n}","validation_output":"[\n {\n \"status-code\": 500,\n \"component\": \"DB\",\n \"status\": \"FAIL\"\n }\n]\n","family":"real-stackoverflow","difficulty":3,"split":"test","source":"stackoverflow-accepted-answer","license":"CC-BY-SA-4.0","question_url":"https://stackoverflow.com/questions/37344329/jq-not-working-on-tag-name-with-dashes-and-numbers","question_title":"jq not working on tag name with dashes and numbers","question_owner":"paul","answer_owner":"fedorqui","answer_id":37344498,"question_score":102,"reviewed":true}
{"id":"so-37563691","request":"Extract the md5 value from the object in the files array where the fileName is \"FOO\".","command":"jq -r '.files[] | select(.fileName==\"FOO\") | .md5'","input_text":"{\"files\": [{\"fileName\": \"FOO\", \"md5\": \"blablabla\"}, {\"fileName\": \"BAR\", \"md5\": \"alaldlafj\"}]}","expected_output":"blablabla\n","validation_input":"{\"files\": [{\"fileName\": \"TEST\", \"md5\": \"abc123\"}, {\"fileName\": \"FOO\", \"md5\": \"xyz789\"}, {\"fileName\": \"BAZ\", \"md5\": \"def456\"}]}","validation_output":"xyz789\n","family":"real-stackoverflow","difficulty":3,"split":"test","source":"stackoverflow-accepted-answer","license":"CC-BY-SA-4.0","question_url":"https://stackoverflow.com/questions/37563691/jq-select-value-from-array","question_title":"jq select value from array","question_owner":"Marvin Effing","answer_owner":"Marvin Effing","answer_id":37567004,"question_score":82,"reviewed":true}
{"id":"so-37577683","request":"Extract the value of the 'hostName' field from all top-level values in a JSON object, regardless of the top-level keys.","command":"jq -r '.[].hostName'","input_text":"{\"key1\": {\"hostName\": \"server1\", \"state\": \"READY\"}, \"key2\": {\"hostName\": \"server2\", \"state\": \"STOPPED\"}}","expected_output":"server1\nserver2\n","validation_input":"{\"abc-123\": {\"hostName\": \"node-alpha\", \"ip\": \"10.0.0.1\"}, \"xyz-789\": {\"hostName\": \"node-beta\", \"ip\": \"10.0.0.2\"}}","validation_output":"node-alpha\nnode-beta\n","family":"real-stackoverflow","difficulty":3,"split":"test","source":"stackoverflow-accepted-answer","license":"CC-BY-SA-4.0","question_url":"https://stackoverflow.com/questions/37577683/how-to-use-jq-to-obtain-the-keys","question_title":"How to use `jq` to obtain the keys","question_owner":"sudhishkr","answer_owner":"Andreas Louv","answer_id":37577805,"question_score":47,"reviewed":true}
{"id":"so-37710718","request":"Create a new JSON object containing a single field named 'channel' whose value is the concatenation of the input's 'profile_type', a dot, and the input's 'channel' value.","command":"jq '{channel: (.profile_type + \".\" + .channel)}'","input_text":"{\"channel\": \"youtube\", \"profile_type\": \"video\", \"member_key\": \"hello\"}","expected_output":"{\n \"channel\": \"video.youtube\"\n}\n","validation_input":"{\"channel\": \"twitch\", \"profile_type\": \"stream\", \"member_key\": \"world\"}","validation_output":"{\n \"channel\": \"stream.twitch\"\n}\n","family":"real-stackoverflow","difficulty":3,"split":"test","source":"stackoverflow-accepted-answer","license":"CC-BY-SA-4.0","question_url":"https://stackoverflow.com/questions/37710718/concat-2-fields-in-json-using-jq","question_title":"Concat 2 fields in JSON using jq","question_owner":"darthsidious","answer_owner":"Anthony Battaglia","answer_id":37710802,"question_score":177,"reviewed":true}
{"id":"so-38061346","request":"Read a stream of multiple JSON objects from stdin and combine them into a single JSON array.","command":"jq -s '.'","input_text":"{\"name\": \"John\", \"email\": \"john@company.com\"}\n{\"name\": \"Brad\", \"email\": \"brad@company.com\"}","expected_output":"[\n {\n \"name\": \"John\",\n \"email\": \"john@company.com\"\n },\n {\n \"name\": \"Brad\",\n \"email\": \"brad@company.com\"\n }\n]\n","validation_input":"{\"id\": 1, \"status\": \"active\"}\n{\"id\": 2, \"status\": \"inactive\"}\n{\"id\": 3, \"status\": \"pending\"}","validation_output":"[\n {\n \"id\": 1,\n \"status\": \"active\"\n },\n {\n \"id\": 2,\n \"status\": \"inactive\"\n },\n {\n \"id\": 3,\n \"status\": \"pending\"\n }\n]\n","family":"real-stackoverflow","difficulty":3,"split":"test","source":"stackoverflow-accepted-answer","license":"CC-BY-SA-4.0","question_url":"https://stackoverflow.com/questions/38061346/jq-output-array-of-json-objects","question_title":"jq: output array of json objects","question_owner":"Mauricio Trajano","answer_owner":"chepner","answer_id":38061430,"question_score":134,"reviewed":true}
{"id":"so-38121740","request":"Filter the 'theList' array to include only objects where the 'id' is either 2 or 4.","command":"jq '.theList[] | select(.id == 2 or .id == 4)'","input_text":"{\"theList\": [{\"id\": 1, \"name\": \"Horst\"}, {\"id\": 2, \"name\": \"Fritz\"}, {\"id\": 3, \"name\": \"Walter\"}, {\"id\": 4, \"name\": \"Gerhart\"}, {\"id\": 5, \"name\": \"Harmut\"}]}","expected_output":"{\n \"id\": 2,\n \"name\": \"Fritz\"\n}\n{\n \"id\": 4,\n \"name\": \"Gerhart\"\n}\n","validation_input":"{\"theList\": [{\"id\": 10, \"name\": \"A\"}, {\"id\": 2, \"name\": \"B\"}, {\"id\": 4, \"name\": \"C\"}, {\"id\": 5, \"name\": \"D\"}]}","validation_output":"{\n \"id\": 2,\n \"name\": \"B\"\n}\n{\n \"id\": 4,\n \"name\": \"C\"\n}\n","family":"real-stackoverflow","difficulty":3,"split":"test","source":"stackoverflow-accepted-answer","license":"CC-BY-SA-4.0","question_url":"https://stackoverflow.com/questions/38121740/how-to-filter-array-of-objects-by-element-property-values-using-jq","question_title":"How to filter array of objects by element property values using jq?","question_owner":"k0pernikus","answer_owner":"André Senra","answer_id":38122029,"question_score":120,"reviewed":true}
{"id":"so-38500363","request":"Select all objects from the input array where the key 'a' equals 'x', collect them into an array, and return the first element of that resulting array.","command":"jq '[.[] | select(.a == \"x\")][0]'","input_text":"[{\"a\": \"x\", \"b\": true}, {\"a\": \"x\", \"b\": false}, {\"a\": \"XML\", \"b\": false}]","expected_output":"{\n \"a\": \"x\",\n \"b\": true\n}\n","validation_input":"[{\"a\": \"y\", \"b\": true}, {\"a\": \"x\", \"b\": 123}, {\"a\": \"x\", \"b\": 456}]","validation_output":"{\n \"a\": \"x\",\n \"b\": 123\n}\n","family":"real-stackoverflow","difficulty":3,"split":"test","source":"stackoverflow-accepted-answer","license":"CC-BY-SA-4.0","question_url":"https://stackoverflow.com/questions/38500363/get-the-first-or-nth-element-in-a-jq-json-parsing","question_title":"get the first (or n'th) element in a jq json parsing","question_owner":"Demian Glait","answer_owner":"hek2mgl","answer_id":38500610,"question_score":128,"reviewed":true}
{"id":"so-38689645","request":"Select the parent object from a JSON structure where a nested field \"details.name\" equals \"James Brown\".","command":"jq 'select(.details.name == \"James Brown\")'","input_text":"{\n \"id\": 1,\n \"details\": {\n \"username\": \"jamesbrown\",\n \"name\": \"James Brown\"\n }\n}","expected_output":"{\n \"id\": 1,\n \"details\": {\n \"username\": \"jamesbrown\",\n \"name\": \"James Brown\"\n }\n}\n","validation_input":"{\n \"id\": 2,\n \"details\": {\n \"username\": \"janedoe\",\n \"name\": \"Jane Doe\"\n }\n}\n{\n \"id\": 3,\n \"details\": {\n \"username\": \"jamesbrown2\",\n \"name\": \"James Brown\"\n }\n}","validation_output":"{\n \"id\": 3,\n \"details\": {\n \"username\": \"jamesbrown2\",\n \"name\": \"James Brown\"\n }\n}\n","family":"real-stackoverflow","difficulty":3,"split":"test","source":"stackoverflow-accepted-answer","license":"CC-BY-SA-4.0","question_url":"https://stackoverflow.com/questions/38689645/how-do-i-print-a-parent-value-of-an-object-when-i-am-already-deep-into-the-objec","question_title":"How do I print a parent value of an object when I am already deep into the object's children?","question_owner":"x3nr0s","answer_owner":"user3899165","answer_id":38693695,"question_score":75,"reviewed":true}
{"id":"so-39228500","request":"Extract all 'name' values from the array located at '.example.\"sub-example\"' in the input JSON object.","command":"jq '.example.\"sub-example\" | .[] | .name'","input_text":"{\n \"example\": {\n \"sub-example\": [\n {\n \"name\": \"123-345\",\n \"tag\": 100\n },\n {\n \"name\": \"234-456\",\n \"tag\": 100\n },\n {\n \"name\": \"4a7-a07a5\",\n \"tag\": 100\n }\n ]\n }\n}","expected_output":"\"123-345\"\n\"234-456\"\n\"4a7-a07a5\"\n","validation_input":"{\n \"example\": {\n \"sub-example\": [\n {\n \"name\": \"alpha\",\n \"tag\": 200\n },\n {\n \"name\": \"beta\",\n \"tag\": 200\n }\n ]\n }\n}","validation_output":"\"alpha\"\n\"beta\"\n","family":"real-stackoverflow","difficulty":3,"split":"test","source":"stackoverflow-accepted-answer","license":"CC-BY-SA-4.0","question_url":"https://stackoverflow.com/questions/39228500/extract-a-specific-field-from-json-output-using-jq","question_title":"Extract a specific field from JSON output using jq","question_owner":"rmb","answer_owner":"aaaaaa123456789","answer_id":39228718,"question_score":160,"reviewed":true}
{"id":"so-40396445","request":"Extract the key, status name, and assignee email address from each issue in the input JSON object's issues array, and output each result as a compact JSON object on a single line.","command":"jq -c '.issues[] | {key, status: .fields.status.name, assignee: .fields.assignee.emailAddress}'","input_text":"{\"issues\": [{\"key\": \"SEA-739\", \"fields\": {\"status\": {\"name\": \"Open\"}, \"assignee\": null}}, {\"key\": \"SEA-738\", \"fields\": {\"status\": {\"name\": \"Resolved\"}, \"assignee\": {\"emailAddress\": \"user2@mycompany.com\"}}}]}","expected_output":"{\"key\":\"SEA-739\",\"status\":\"Open\",\"assignee\":null}\n{\"key\":\"SEA-738\",\"status\":\"Resolved\",\"assignee\":\"user2@mycompany.com\"}\n","validation_input":"{\"issues\": [{\"key\": \"PROJ-101\", \"fields\": {\"status\": {\"name\": \"In Progress\"}, \"assignee\": {\"emailAddress\": \"dev@example.com\"}}}, {\"key\": \"PROJ-102\", \"fields\": {\"status\": {\"name\": \"Closed\"}, \"assignee\": null}}]}","validation_output":"{\"key\":\"PROJ-101\",\"status\":\"In Progress\",\"assignee\":\"dev@example.com\"}\n{\"key\":\"PROJ-102\",\"status\":\"Closed\",\"assignee\":null}\n","family":"real-stackoverflow","difficulty":3,"split":"test","source":"stackoverflow-accepted-answer","license":"CC-BY-SA-4.0","question_url":"https://stackoverflow.com/questions/40396445/get-outputs-from-jq-on-a-single-line","question_title":"Get outputs from jq on a single line","question_owner":"Jitesh Sojitra","answer_owner":"hmedia1","answer_id":40396556,"question_score":187,"reviewed":true}
{"id":"so-42051601","request":"From a JSON object with a 'data' field, extract the values of keys that case-insensitively match the pattern 'what a burger'.","command":"jq '.data | to_entries | map(select(.key | match(\"what a burger\";\"i\"))) | map(.value)'","input_text":"{\n \"data\": {\n \"what a burger\": [1, 2, 3],\n \"wap\": [66],\n \"the map\": [11, 20],\n \"H. Incandenza\": [1, 1],\n \"What a burger\": [\"a\", \"a\", 3]\n }\n}","expected_output":"[\n [\n 1,\n 2,\n 3\n ],\n [\n \"a\",\n \"a\",\n 3\n ]\n]\n","validation_input":"{\n \"data\": {\n \"WHAT A BURGER\": [10, 20],\n \"other\": [5],\n \"What a Burger\": [\"x\", \"y\"]\n }\n}","validation_output":"[\n [\n 10,\n 20\n ],\n [\n \"x\",\n \"y\"\n ]\n]\n","family":"real-stackoverflow","difficulty":3,"split":"test","source":"stackoverflow-accepted-answer","license":"CC-BY-SA-4.0","question_url":"https://stackoverflow.com/questions/42051601/pattern-matching-field-names-with-jq","question_title":"Pattern matching field names with jq","question_owner":"manu","answer_owner":"koalo","answer_id":42051804,"question_score":45,"reviewed":true}
{"id":"so-42245288","request":"Append a new message object to the messages array within the data object of the input JSON.","command":"jq '.data.messages += [{\"date\": \"2010-01-07T19:55:99.999Z\", \"xml\": \"xml_samplesheet_2017_01_07_run_09.xml\", \"status\": \"OKKK\", \"message\": \"metadata loaded into iRODS successfullyyyyy\"}]'","input_text":"{\"report\": \"1.0\", \"data\": {\"date\": \"2010-01-07\", \"messages\": [{\"date\": \"2010-01-07T19:58:42.949Z\", \"xml\": \"xml_samplesheet_2017_01_07_run_09.xml\", \"status\": \"OK\", \"message\": \"metadata loaded into iRODS successfully\"}, {\"date\": \"2010-01-07T20:22:46.949Z\", \"xml\": \"xml_samplesheet_2017_01_07_run_09.xml\", \"status\": \"NOK\", \"message\": \"metadata duplicated into iRODS\"}]}}","expected_output":"{\n \"report\": \"1.0\",\n \"data\": {\n \"date\": \"2010-01-07\",\n \"messages\": [\n {\n \"date\": \"2010-01-07T19:58:42.949Z\",\n \"xml\": \"xml_samplesheet_2017_01_07_run_09.xml\",\n \"status\": \"OK\",\n \"message\": \"metadata loaded into iRODS successfully\"\n },\n {\n \"date\": \"2010-01-07T20:22:46.949Z\",\n \"xml\": \"xml_samplesheet_2017_01_07_run_09.xml\",\n \"status\": \"NOK\",\n \"message\": \"metadata duplicated into iRODS\"\n },\n {\n \"date\": \"2010-01-07T19:55:99.999Z\",\n \"xml\": \"xml_samplesheet_2017_01_07_run_09.xml\",\n \"status\": \"OKKK\",\n \"message\": \"metadata loaded into iRODS successfullyyyyy\"\n }\n ]\n }\n}\n","validation_input":"{\"report\": \"2.0\", \"data\": {\"date\": \"2011-01-07\", \"messages\": [{\"date\": \"2011-01-07T10:00:00.000Z\", \"xml\": \"test.xml\", \"status\": \"OK\", \"message\": \"test msg\"}]}}","validation_output":"{\n \"report\": \"2.0\",\n \"data\": {\n \"date\": \"2011-01-07\",\n \"messages\": [\n {\n \"date\": \"2011-01-07T10:00:00.000Z\",\n \"xml\": \"test.xml\",\n \"status\": \"OK\",\n \"message\": \"test msg\"\n },\n {\n \"date\": \"2010-01-07T19:55:99.999Z\",\n \"xml\": \"xml_samplesheet_2017_01_07_run_09.xml\",\n \"status\": \"OKKK\",\n \"message\": \"metadata loaded into iRODS successfullyyyyy\"\n }\n ]\n }\n}\n","family":"real-stackoverflow","difficulty":3,"split":"test","source":"stackoverflow-accepted-answer","license":"CC-BY-SA-4.0","question_url":"https://stackoverflow.com/questions/42245288/add-new-element-to-existing-json-array-with-jq","question_title":"Add new element to existing JSON array with jq","question_owner":"Felipe","answer_owner":"Inian","answer_id":42248841,"question_score":133,"reviewed":true}
{"id":"so-42427725","request":"Convert an array of objects with 'name' and 'value' fields into a single object where each key is the 'name' value and the corresponding value is the original object.","command":"jq 'map({(.name): .}) | add'","input_text":"[\n {\"name\": \"A\", \"value\": \"1\"},\n {\"name\": \"B\", \"value\": \"5\"},\n {\"name\": \"E\", \"value\": \"8\"}\n]","expected_output":"{\n \"A\": {\n \"name\": \"A\",\n \"value\": \"1\"\n },\n \"B\": {\n \"name\": \"B\",\n \"value\": \"5\"\n },\n \"E\": {\n \"name\": \"E\",\n \"value\": \"8\"\n }\n}\n","validation_input":"[\n {\"name\": \"X\", \"value\": \"10\"},\n {\"name\": \"Y\", \"value\": \"20\"}\n]","validation_output":"{\n \"X\": {\n \"name\": \"X\",\n \"value\": \"10\"\n },\n \"Y\": {\n \"name\": \"Y\",\n \"value\": \"20\"\n }\n}\n","family":"real-stackoverflow","difficulty":3,"split":"test","source":"stackoverflow-accepted-answer","license":"CC-BY-SA-4.0","question_url":"https://stackoverflow.com/questions/42427725/using-jq-convert-array-of-objects-to-object-with-named-keys","question_title":"Using jq, convert array of objects to object with named keys","question_owner":"Mike N","answer_owner":"peak","answer_id":42428341,"question_score":62,"reviewed":true}
{"id":"so-42746828","request":"Filter objects in a JSON array to keep only those where none of the strings in the \"imageTags\" array contain the text \"latest\".","command":"jq '[.[] | select([.imageTags[] | contains(\"latest\")] | any | not)]'","input_text":"[\n {\n \"imagePushedAt\": 100,\n \"imageTags\": [\"v1\", \"stable\"]\n },\n {\n \"imagePushedAt\": 200,\n \"imageTags\": [\"v2\", \"latest\"]\n },\n {\n \"imagePushedAt\": 300,\n \"imageTags\": [\"v3\"]\n }\n]","expected_output":"[\n {\n \"imagePushedAt\": 100,\n \"imageTags\": [\n \"v1\",\n \"stable\"\n ]\n },\n {\n \"imagePushedAt\": 300,\n \"imageTags\": [\n \"v3\"\n ]\n }\n]\n","validation_input":"[\n {\n \"imagePushedAt\": 400,\n \"imageTags\": [\"release-candidate\"]\n },\n {\n \"imagePushedAt\": 500,\n \"imageTags\": [\"latest-build\"]\n },\n {\n \"imagePushedAt\": 600,\n \"imageTags\": []\n }\n]","validation_output":"[\n {\n \"imagePushedAt\": 400,\n \"imageTags\": [\n \"release-candidate\"\n ]\n },\n {\n \"imagePushedAt\": 600,\n \"imageTags\": []\n }\n]\n","family":"real-stackoverflow","difficulty":3,"split":"test","source":"stackoverflow-accepted-answer","license":"CC-BY-SA-4.0","question_url":"https://stackoverflow.com/questions/42746828/jq-how-to-query-for-array-values-that-dont-contain-text-foo","question_title":"jq: how to query for array values that don't contain text "foo"?","question_owner":"Gavriel Fishel","answer_owner":"J. Doe","answer_id":42747910,"question_score":92,"reviewed":true}
{"id":"so-43221453","request":"Group an array of objects by their 'component' field and output separate objects for each component, where the key is the component name and the value is an array of the associated 'ip' addresses.","command":"jq 'group_by(.component)[] | {(.[0].component): [.[] | .ip]}'","input_text":"[\n {\"ip\": \"1.1.1.1\", \"component\": \"name1\"},\n {\"ip\": \"1.1.1.2\", \"component\": \"name1\"},\n {\"ip\": \"1.1.1.3\", \"component\": \"name2\"},\n {\"ip\": \"1.1.1.4\", \"component\": \"name2\"}\n]","expected_output":"{\n \"name1\": [\n \"1.1.1.1\",\n \"1.1.1.2\"\n ]\n}\n{\n \"name2\": [\n \"1.1.1.3\",\n \"1.1.1.4\"\n ]\n}\n","validation_input":"[\n {\"ip\": \"2.2.2.1\", \"component\": \"web\"},\n {\"ip\": \"2.2.2.2\", \"component\": \"db\"},\n {\"ip\": \"2.2.2.3\", \"component\": \"web\"}\n]","validation_output":"{\n \"db\": [\n \"2.2.2.2\"\n ]\n}\n{\n \"web\": [\n \"2.2.2.1\",\n \"2.2.2.3\"\n ]\n}\n","family":"real-stackoverflow","difficulty":3,"split":"test","source":"stackoverflow-accepted-answer","license":"CC-BY-SA-4.0","question_url":"https://stackoverflow.com/questions/43221453/jq-group-and-key-by-property","question_title":"jq: group and key by property","question_owner":"replay","answer_owner":"replay","answer_id":43221520,"question_score":57,"reviewed":true}
{"id":"so-43291389","request":"Extract the absoluteNumber, airedEpisodeNumber, episodeName, and overview from each object in the data array, joining them with a pipe delimiter per line.","command":"jq -r '.data[] | [.absoluteNumber, .airedEpisodeNumber, .episodeName, .overview] | join(\"|\")'","input_text":"{\"data\": [{\"absoluteNumber\": 51, \"airedEpisodeNumber\": 6, \"episodeName\": \"We Will Rise\", \"overview\": \"Clarke and Roan must work together.\"}]}","expected_output":"51|6|We Will Rise|Clarke and Roan must work together.\n","validation_input":"{\"data\": [{\"absoluteNumber\": 10, \"airedEpisodeNumber\": 1, \"episodeName\": \"Pilot\", \"overview\": \"The beginning.\"}, {\"absoluteNumber\": 11, \"airedEpisodeNumber\": 2, \"episodeName\": \"Second\", \"overview\": \"Continuation.\"}]}","validation_output":"10|1|Pilot|The beginning.\n11|2|Second|Continuation.\n","family":"real-stackoverflow","difficulty":3,"split":"test","source":"stackoverflow-accepted-answer","license":"CC-BY-SA-4.0","question_url":"https://stackoverflow.com/questions/43291389/using-jq-to-assign-multiple-output-variables","question_title":"using jq to assign multiple output variables","question_owner":"user2328273","answer_owner":"Bertrand Martel","answer_id":43293515,"question_score":43,"reviewed":true}
{"id":"so-43522133","request":"Rename the key \"veg\" to \"fruit2\" and \"worker\" to \"job\" in each object of a JSON array, removing the original keys.","command":"jq '[.[] | .[\"fruit2\"] = .veg | .[\"job\"] = .worker | del(.veg, .worker)]'","input_text":"[{\"fruit\":\"strawberry\",\"veg\":\"apple\",\"worker\":\"gardener\"}]","expected_output":"[\n {\n \"fruit\": \"strawberry\",\n \"fruit2\": \"apple\",\n \"job\": \"gardener\"\n }\n]\n","validation_input":"[{\"fruit\":\"banana\",\"veg\":\"carrot\",\"worker\":\"farmer\"}]","validation_output":"[\n {\n \"fruit\": \"banana\",\n \"fruit2\": \"carrot\",\n \"job\": \"farmer\"\n }\n]\n","family":"real-stackoverflow","difficulty":3,"split":"test","source":"stackoverflow-accepted-answer","license":"CC-BY-SA-4.0","question_url":"https://stackoverflow.com/questions/43522133/using-jq-how-can-i-replace-the-name-of-a-key-with-something-else","question_title":"Using jq how can I replace the name of a key with something else","question_owner":"user486670","answer_owner":"RomanPerekhrest","answer_id":43522716,"question_score":53,"reviewed":true}
{"id":"so-44656515","request":"Extract the value of the 'name' field from a JSON object as raw text without surrounding quotes.","command":"jq -r '.name'","input_text":"{\"name\": \"Google\", \"id\": 1}","expected_output":"Google\n","validation_input":"{\"name\": \"Apple\", \"id\": 2}","validation_output":"Apple\n","family":"real-stackoverflow","difficulty":3,"split":"test","source":"stackoverflow-accepted-answer","license":"CC-BY-SA-4.0","question_url":"https://stackoverflow.com/questions/44656515/how-to-remove-double-quotes-in-jq-output-for-parsing-json-files-in-bash","question_title":"How to remove double-quotes in jq output for parsing json files in bash?","question_owner":"Chris F","answer_owner":"Charles Duffy","answer_id":44656583,"question_score":800,"reviewed":true}
{"id":"so-45165303","request":"For each ticket in the 'tickets' array, output a CSV line where the 'tags' array is joined into a single comma-separated string field.","command":"jq -r '.tickets[] | [.created_at, .id, .via.channel, (.tags | join(\",\"))] | @csv'","input_text":"{\n \"tickets\": [\n {\n \"created_at\": \"2016-02-02T10:00:00Z\",\n \"id\": 99999,\n \"via\": { \"channel\": \"web\" },\n \"tags\": [\"tag1\", \"tag2\", \"tag3\"]\n }\n ]\n}","expected_output":"\"2016-02-02T10:00:00Z\",99999,\"web\",\"tag1,tag2,tag3\"\n","validation_input":"{\n \"tickets\": [\n {\n \"created_at\": \"2023-01-01T00:00:00Z\",\n \"id\": 1,\n \"via\": { \"channel\": \"email\" },\n \"tags\": [\"urgent\", \"bug\"]\n },\n {\n \"created_at\": \"2023-01-02T00:00:00Z\",\n \"id\": 2,\n \"via\": { \"channel\": \"api\" },\n \"tags\": []\n }\n ]\n}","validation_output":"\"2023-01-01T00:00:00Z\",1,\"email\",\"urgent,bug\"\n\"2023-01-02T00:00:00Z\",2,\"api\",\"\"\n","family":"real-stackoverflow","difficulty":3,"split":"test","source":"stackoverflow-accepted-answer","license":"CC-BY-SA-4.0","question_url":"https://stackoverflow.com/questions/45165303/how-to-combine-an-array-into-a-single-string-value-when-using-csv-output-in-jq","question_title":"How to combine an array into a single string value when using CSV output in jq?","question_owner":"Emre Sevinç","answer_owner":"zwer","answer_id":45165687,"question_score":45,"reviewed":true}
{"id":"so-45523425","request":"Extract the text field from all objects in the response array, ignoring non-object entries.","command":"jq '.response[] | objects | .text'","input_text":"{\"response\": [1000, {\"id\": 1, \"text\": \"blabla\"}, {\"id\": 2, \"text\": \"hello world\"}]}","expected_output":"\"blabla\"\n\"hello world\"\n","validation_input":"{\"response\": [\"error\", {\"id\": 5, \"text\": \"first post\"}, {\"id\": 6, \"text\": \"second post\"}, null]}","validation_output":"\"first post\"\n\"second post\"\n","family":"real-stackoverflow","difficulty":3,"split":"test","source":"stackoverflow-accepted-answer","license":"CC-BY-SA-4.0","question_url":"https://stackoverflow.com/questions/45523425/getting-all-the-values-of-an-array-with-jq","question_title":"getting all the values of an array with jq","question_owner":"Miss Alena","answer_owner":"peak","answer_id":45524015,"question_score":80,"reviewed":true}
{"id":"so-46131727","request":"Extract the 'foo' and 'bar' values from the nested 'fmep' object and print them on the same line separated by a space.","command":"jq -r '.fmep | \"\\(.foo) \\(.bar)\"'","input_text":"{\n \"fmep\": {\n \"foo\": 112,\n \"bar\": 234324,\n \"cat\": 21343423\n }\n}","expected_output":"112 234324\n","validation_input":"{\n \"fmep\": {\n \"foo\": 5,\n \"bar\": 10,\n \"cat\": 15\n }\n}","validation_output":"5 10\n","family":"real-stackoverflow","difficulty":3,"split":"test","source":"stackoverflow-accepted-answer","license":"CC-BY-SA-4.0","question_url":"https://stackoverflow.com/questions/46131727/printing-multiple-values-on-the-same-line","question_title":"Printing multiple values on the same line","question_owner":"Mickster","answer_owner":"jq170727","answer_id":46131963,"question_score":58,"reviewed":true}
{"id":"so-47023795","request":"Remove the top-level 'pages' key and its value from the JSON object, keeping all other keys intact.","command":"jq 'del(.pages)'","input_text":"{\n \"pages\": {\n \"elems\": { \"id\": 1 }\n },\n \"actions\": {\n \"pages\": { \"id\": 2 }\n }\n}","expected_output":"{\n \"actions\": {\n \"pages\": {\n \"id\": 2\n }\n }\n}\n","validation_input":"{\n \"pages\": {\n \"title\": \"Home\"\n },\n \"users\": [\n { \"name\": \"Alice\" }\n ],\n \"settings\": {\n \"theme\": \"dark\"\n }\n}","validation_output":"{\n \"users\": [\n {\n \"name\": \"Alice\"\n }\n ],\n \"settings\": {\n \"theme\": \"dark\"\n }\n}\n","family":"real-stackoverflow","difficulty":3,"split":"test","source":"stackoverflow-accepted-answer","license":"CC-BY-SA-4.0","question_url":"https://stackoverflow.com/questions/47023795/removing-a-key-from-parent-object-with-jq","question_title":"Removing a key from parent object with jq","question_owner":"Nicholas","answer_owner":"jq170727","answer_id":47024050,"question_score":44,"reviewed":true}
{"id":"so-48426052","request":"Given a JSON array of user objects, extract and print the 'username' field from each object on a new line.","command":"jq -r '.[].username'","input_text":"[\n {\n \"username\": \"jdoe\",\n \"name\": \"John Doe\"\n },\n {\n \"username\": \"jadoe\",\n \"name\": \"Jane Doe\"\n }\n]","expected_output":"jdoe\njadoe\n","validation_input":"[\n {\n \"username\": \"alice\",\n \"name\": \"Alice Smith\"\n },\n {\n \"username\": \"bob\",\n \"name\": \"Bob Jones\"\n }\n]","validation_output":"alice\nbob\n","family":"real-stackoverflow","difficulty":3,"split":"test","source":"stackoverflow-accepted-answer","license":"CC-BY-SA-4.0","question_url":"https://stackoverflow.com/questions/48426052/how-to-extract-a-field-from-each-object-in-an-array-with-jq","question_title":"How to extract a field from each object in an array with jq?","question_owner":"Chris F","answer_owner":"John Kugelman","answer_id":48426543,"question_score":84,"reviewed":true}
{"id":"so-49632521","request":"Add a new key-value pair '\"operation\": \"delete\"' to the 'fields' object located at .module.data.item_i77f664a2.fields in a JSON object.","command":"jq '.module.data.item_i77f664a2.fields += {\"operation\": \"delete\"}'","input_text":"{\"success\": true, \"module\": {\"data\": {\"item_i77f664a2\": {\"id\": \"i77f664a2\", \"fields\": {\"cartItemId\": 2012636322}, \"type\": \"biz\"}}}}","expected_output":"{\n \"success\": true,\n \"module\": {\n \"data\": {\n \"item_i77f664a2\": {\n \"id\": \"i77f664a2\",\n \"fields\": {\n \"cartItemId\": 2012636322,\n \"operation\": \"delete\"\n },\n \"type\": \"biz\"\n }\n }\n }\n}\n","validation_input":"{\"success\": false, \"module\": {\"data\": {\"item_i77f664a2\": {\"id\": \"other-id\", \"fields\": {\"qty\": 5}, \"type\": \"retail\"}}}}","validation_output":"{\n \"success\": false,\n \"module\": {\n \"data\": {\n \"item_i77f664a2\": {\n \"id\": \"other-id\",\n \"fields\": {\n \"qty\": 5,\n \"operation\": \"delete\"\n },\n \"type\": \"retail\"\n }\n }\n }\n}\n","family":"real-stackoverflow","difficulty":3,"split":"test","source":"stackoverflow-accepted-answer","license":"CC-BY-SA-4.0","question_url":"https://stackoverflow.com/questions/49632521/how-to-add-a-field-to-a-json-object-with-the-jq-command","question_title":"How to add a field to a JSON object with the jq command?","question_owner":"Joe","answer_owner":"peak","answer_id":49632947,"question_score":46,"reviewed":true}
{"id":"so-50868203","request":"Filter a JSON array of objects to keep only those where the 'Address' field starts with a digit.","command":"jq '[.[] | select(.Address | test(\"^[0-9]\"))]'","input_text":"[{\"Address\": \"The Sq\"}, {\"Address\": \"1 Bridge Rd\"}]","expected_output":"[\n {\n \"Address\": \"1 Bridge Rd\"\n }\n]\n","validation_input":"[{\"Address\": \"No Number St\"}, {\"Address\": \"99 Main Ave\"}, {\"Address\": \"Apt 5\"}]","validation_output":"[\n {\n \"Address\": \"99 Main Ave\"\n }\n]\n","family":"real-stackoverflow","difficulty":3,"split":"test","source":"stackoverflow-accepted-answer","license":"CC-BY-SA-4.0","question_url":"https://stackoverflow.com/questions/50868203/filter-by-regex-in-jq","question_title":"Filter by Regex in JQ","question_owner":"user49","answer_owner":"peak","answer_id":50868294,"question_score":48,"reviewed":true}
{"id":"so-52065570","request":"Read a stream of JSON objects from stdin, extract the 'duration' field from each, and output the sum of all durations as a single number.","command":"jq -s '[.[].duration] | add'","input_text":"{\"duration\": 1211789}\n{\"duration\": 1211789}\n{\"duration\": 373585}","expected_output":"2797163\n","validation_input":"{\"duration\": 100}\n{\"duration\": 200}\n{\"duration\": 300}","validation_output":"600\n","family":"real-stackoverflow","difficulty":3,"split":"test","source":"stackoverflow-accepted-answer","license":"CC-BY-SA-4.0","question_url":"https://stackoverflow.com/questions/52065570/how-do-i-sum-all-numbers-from-output-of-jq","question_title":"How do I sum all numbers from output of jq","question_owner":"toy","answer_owner":"Charles Duffy","answer_id":52065738,"question_score":40,"reviewed":true}
|