jq

How to get the output of jq in single line?

杀马特。学长 韩版系。学妹 提交于 2021-02-08 05:10:32
问题 I have used jq with aws cli to print the instances . Eg: Retrieve instances list aws ec2 describe-instances --filters "Name=tag:bld_env,Values=test" --output json > all-inst.json Jq to print instances id : jq -r '.Reservations[].Instances[].InstanceId' all-inst.json Output of Jq: i-09e0d805cc i-091a61038 i-07d3022 i-0428ac7c4c i-970dc5c4d99 i-014c4ea i-0ac924df i-031f6 and so on.. I want to print them in a line like this : i-09e0d805cc,i-091a61038,i-07d3022,i-0428ac7c4c,i-970dc5c4d99,i

Get json object that has latest timestamp using jq

北城以北 提交于 2021-02-08 05:09:16
问题 I have a below json file but I'm struggling to only display the description with the latest createdDate . I tried with > < todateiso8601? now and a few more but I can't get this to work. Would anyone be able to help? JSON: { "items": [ { "createdDate": 1543585940, "id": "awefef", "description": "this is description 1" }, { "createdDate": 1555324487, "id": "hjkvhuk", "description": "this is description 2" }, { "createdDate": 1547034297, "id": "xdfxdfv", "description": "this is description 3" }

Loop through JSON object using jq

半城伤御伤魂 提交于 2021-02-07 23:23:13
问题 This is what my JSON array of objects looks like: [ { "Description": "Description 1", "OutputKey": "OutputKey 1", "OutputValue": "OutputValue 1" }, { "Description": "Description 2", "OutputKey": "OutputKey 2", "OutputValue": "OutputValue 2" }, { "Description": "Description 3", "OutputKey": "OutputKey 3", "OutputValue": "OutputValue 3" }, { "Description": "Description 4", "OutputKey": "OutputKey 4", "OutputValue": "OutputValue 4" }, { "Description": "Description 5", "OutputKey": "OutputKey 5",

How to add a header to CSV export in jq?

会有一股神秘感。 提交于 2021-02-07 04:53:05
问题 I'm taking a modified command from the jq tutorial: curl 'https://api.github.com/repos/stedolan/jq/commits?per_page=5' \ | jq -r -c '.[] | {message: .commit.message, name: .commit.committer.name} | [.[]] | @csv' Which does csv export well, but missing the headers as the top: "Fix README","Nicolas Williams" "README: send questions to SO and Freenode","Nicolas Williams" "usage() should check fprintf() result (fix #771)","Nicolas Williams" "Use jv_mem_alloc() in compile.c (fix #771)","Nicolas

Java多线程游戏仿真实例分享

十年热恋 提交于 2021-02-06 12:34:40
这是一篇学习分享博客,这篇博客将会介绍以下几项内容: 1、如何让一个程序同时做多件事?(多线程的创建、多线程的应用) 2、如何让小球在画面中真实地动起来?(赋予小球匀速直线、自由落体、上抛等向量运动) 3、多线程游戏仿真实例分享(飞机大战、接豆人、双线挑战三个游戏实例) 涉及的知识点有:多线程的应用、双缓冲绘图、小球的向量运动、游戏的逻辑判断、键盘监听器的使用、二维数组的使用、添加音乐效果等 游戏效果: 怎么样?如果觉得还不错的话就请继续看下去吧! 热身 第一步:创建画布 心急吃不了热豆腐,我们先从最简单的创建画布开始。 首先我们创建一个窗体,然后设置一些参数,从窗体中取得画笔,尝试在画布中心画一个图形,以下是参考代码: import java . awt . FlowLayout ; import java . awt . Graphics ; import java . awt . event . ActionEvent ; import java . awt . event . ActionListener ; import javax . swing . JButton ; import javax . swing . JFrame ; public class Frame { //声明画布对象 public Graphics g ; //主函数 public static

jq: pass variable argument to be used as filter [duplicate]

二次信任 提交于 2021-02-05 12:26:20
问题 This question already has answers here : jq: pass string argument without quotes (3 answers) Closed 2 years ago . How do I pass a variable argument to JQ program that will be used as a filter. Since by default --arg passes the argument as a a string wrapped with quotes the same cannot be used to apply a filter. here is the JQ program that finds a particular path in the given json and adds a static key value to that path but doesn't work because of the quotes issue. --argjson name '{ "pattern"

jq: pass variable argument to be used as filter [duplicate]

时光毁灭记忆、已成空白 提交于 2021-02-05 12:25:02
问题 This question already has answers here : jq: pass string argument without quotes (3 answers) Closed 2 years ago . How do I pass a variable argument to JQ program that will be used as a filter. Since by default --arg passes the argument as a a string wrapped with quotes the same cannot be used to apply a filter. here is the JQ program that finds a particular path in the given json and adds a static key value to that path but doesn't work because of the quotes issue. --argjson name '{ "pattern"

convert JSON array to bash array preserving whitespaces

旧城冷巷雨未停 提交于 2021-02-05 11:39:53
问题 I want to transform JSON file into bash array of strings that i will later be able to iterate over. My JSON structure is as follows: [ { "USERID": "TMCCP", "CREATED_DATE": "31/01/2020 17:52" }, { "USERID": "TMCCP", "CREATED_DATE": "31/01/2020 17:52" } ] And this is my bash script: test_cases=($(jq -c '.[]' data.json)) echo ${test_cases[0]} echo ${test_cases[1]} echo ${test_cases[2]} echo ${test_cases[3]} As you can see it returns array with 4 elements instead of 2. Output: {"USERID":"TMCCP",

Merge json files using jq (one input object per file -> one larger output object, not a list)

不羁的心 提交于 2021-02-05 09:28:46
问题 I am merging two json files using "jq -s . file1 file2", but I want them to get merged without comma separation. Also it shouldn't start with [] file 1: { "node1": { "Environment": "PRD", "OS": "linux" }, "node2": { "Environment": "NPR", "OS": "linux" } } file 2: { "node3": { "Environment": "PRD", "OS": "linux" }, "node4": { "Environment": "NPR", "OS": "linux" } } Output using jq -s . file 1 file 2 [ { "node1": { "Environment": "PRD", "OS": "linux" }, "node2": { "Environment": "NPR", "OS":

Merge json files using jq (one input object per file -> one larger output object, not a list)

谁说胖子不能爱 提交于 2021-02-05 09:27:38
问题 I am merging two json files using "jq -s . file1 file2", but I want them to get merged without comma separation. Also it shouldn't start with [] file 1: { "node1": { "Environment": "PRD", "OS": "linux" }, "node2": { "Environment": "NPR", "OS": "linux" } } file 2: { "node3": { "Environment": "PRD", "OS": "linux" }, "node4": { "Environment": "NPR", "OS": "linux" } } Output using jq -s . file 1 file 2 [ { "node1": { "Environment": "PRD", "OS": "linux" }, "node2": { "Environment": "NPR", "OS":