jq

Get array with all values for certain key in JSON wih JQ

自作多情 提交于 2021-02-05 08:14:15
问题 Say I have the following JSON: { "a": 0, "b": "c", "d": { "e": { "f": "g", "comments": { "leading": "Lorem ipsum" }, "h": { "i": { "j": [ 1, 2 ] }, "comments": { "trailing": "dolor sit" } } }, "comments": { "leading": "amet." } } } I want to get an array with the values of all the fields named comments (which can be nested in any level). So, in this case I want to get: [ { "leading": "Lorem ipsum" }, { "trailing": "dolor sit" }, { "leading": "amet." } ] The order of the array doesn't matter.

Bash and jq nested loops on json

纵然是瞬间 提交于 2021-02-05 06:47:25
问题 I try to use jq to parse a json file and use it in a bash script, but i'm having some difficulties. The json [ {"annonce_id":"123","photos":["url_01"],"titre_slug":"slug1"}, {"annonce_id":"456","photos":["url_11","url_12"],"titre_slug":"slug2"}, {"annonce_id":"7890","photos":["url_31"],"titre_slug":"slug3"}, {"annonce_id":"1234","photos":["url_41"],"titre_slug":"slug4"}, {"annonce_id":"5678","photos":["url_51"],"titre_slug":"slug5"}, {"annonce_id":"90123","photos":["url_61"],"titre_slug":

jq with multiple inputs from different sources

為{幸葍}努か 提交于 2021-02-05 05:59:05
问题 How can we mix different input sources when using jq ? For a specific usecase, I'd like to add some data from a file into a feed that was pipe in stdout. $ echo '[{"a": 1}]' > /tmp/a1 $ echo '[{"a": 2}]' > /tmp/a2 $ jq --slurp '.[0] + .[1]' /tmp/a1 /tmp/a2 [ { "a": 1 }, { "a": 2 } ] $ cat /tmp/a1 | jq --slurp '.[0] + .[1]' /tmp/a2 # Expecting the same result [ { "a": 2 } ] As you can see, the last command didn't interpret the piped data. Right now, I'm forced to save the output from the first

jq - How to select objects based on a 'blacklist' of property values

冷暖自知 提交于 2021-02-04 20:57:32
问题 Similar to the question answered here: jq - How to select objects based on a 'whitelist' of property values, I'd like to select objects based on a blacklist of property values... The following works fine as a whitelist: curl -s 'https://api.github.com/repos/stedolan/jq/commits?per_page=10' | jq --argjson whitelist '["stedolan", "dtolnay"]' '.[] | select(.author.login == $whitelist[]) | {author: .author.login, message: .commit.message}' { "author": "dtolnay", "message": "Remove David from

jq - How to select objects based on a 'blacklist' of property values

半城伤御伤魂 提交于 2021-02-04 20:55:46
问题 Similar to the question answered here: jq - How to select objects based on a 'whitelist' of property values, I'd like to select objects based on a blacklist of property values... The following works fine as a whitelist: curl -s 'https://api.github.com/repos/stedolan/jq/commits?per_page=10' | jq --argjson whitelist '["stedolan", "dtolnay"]' '.[] | select(.author.login == $whitelist[]) | {author: .author.login, message: .commit.message}' { "author": "dtolnay", "message": "Remove David from

Replace an attribute or key in JSON using jq or sed

我怕爱的太早我们不能终老 提交于 2021-02-04 16:01:07
问题 Have a big json like this "envConfig": { "environmentName": { "versions": [ { "name": "version1", "value": "Dev" }, { "name": "version2", "host": "qa" } ], "userRoles": [ { "name": "Roles", "entry": [ { "name": "employees", "value": "rwx" }, { "name": "customers", "value": "rx" } ] } ] } }, I wanted to change the JSON attribute from "environmentName" to "prod". Below is the output i am expecting "envConfig": { "prod": { "versions": [ ... ], "userRoles": [ ... ] } } Tried with sed command as

Kubernetes 探针详解!

时光毁灭记忆、已成空白 提交于 2021-02-04 02:42:16
: 你填了吗?10人将获赠CNCF商店$100美元礼券! 来参与2020年CNCF中国云原生调查 问卷链接( https://www.wjx.cn/jq/97146486.aspx ) 配置 readiness、liveness 和 startup 探针可以处理不健康的 Pod,本文介绍了三种类型的探针、最佳实践和有关工具,以检测可能存在的配置问题。 作者:Yitaek Hwang 翻译:Bach(才云) 校对:木子(才云) 分 布式系统和微服务体系结构的挑战之一是自动检测不正常的应用程序,并将请求(request)重新路由到其他可用系统,恢复损坏的组件。健康检查是应对该挑战的一种可靠方法。 使用 Kubernetes,可以通过探针配置运行状况检查,以确定每个 Pod 的状态。 默认情况下,Kubernetes 会观察 Pod 生命周期,并在容器从挂起(pending)状态转移到成功(succeeded)状态时,将流量路由到 Pod。Kubelet 会监控崩溃的应用程序,并重新启动 Pod 进行恢复。许多开发人员认为这样的基本设置就足够了,尤其是当 Pod 内的应用程序还配置了守护进程管理器(例如 Node.js 的 PM2)时。 但有一种意外情况,当 Kubernetes 在所有容器启动后,认为 Pod 是健康且可以接受请求时,但应用程序在实际准备就绪之前就已收到流量

Mybatis plus通用字段自动填充的最佳实践总结

a 夏天 提交于 2021-01-31 15:29:24
在进行持久层数据维护(新增或修改)的时候,我们通常需要记录一些非业务字段,比如:create_time、update_time、update_by、create_by等用来维护数据记录的创建时间、修改时间、修改人、创建人等信息。通常情况下我们需要对这些字段进行手动赋值。赋值的过程也比较冗余,都是重复操作。 通常是为create_time赋值为系统的当前时间、update_time赋值为系统修改操作执行时的当前时间。 create_by(创建人)、update_by(修改人)赋值为当前的登录用户的用户名 xxxYyyZzz.setUpdateBy("zimug"); //数据记录更新操作人 xxxYyyZzz.setUpdateTime(new Date()); //数据记录更新操作的时间 Mybatis plus 为我们提供了一种一劳永逸的自动化赋值方式。 一、调整数据库表结构 以mysql数据库环境下的xxx_yyy_zzz表为例,在原有的表字段的基础上,添加下面的四个通用数据维护字段。 ALTER TABLE `xxx_yyy_zzz` ADD COLUMN `create_by` VARCHAR(64) NOT NULL COMMENT '本条记录创建人'; ALTER TABLE `xxx_yyy_zzz` ADD COLUMN `create_time` DATETIME

Get a list of AWS pipelines ready for stage approval

和自甴很熟 提交于 2021-01-29 21:55:03
问题 I have 40+ pipelines that I need to approve from dev to QA and then QA to stage. I am working on a script to use AWS CLI commands to do do. I have been able to do that for a single pipeline where I know that the specific pipeline is ready to be approved. aws codepipeline put-approval-result --cli-input-json file://TestPipeline.json This is how I gathered the information for the approval for a single pipeline aws codepipeline get-pipeline-state --name Pipeline-Ready-for-Approval What I am

How do I concatenate dummy values in JQ based on field value, and then CSV-aggregate these concatenations?

我的梦境 提交于 2021-01-29 15:28:20
问题 In my bash script, when I run the following jq against my curl result: curl -u someKey:someSecret someURL 2>/dev/null | jq -r '.schema' | jq -r -c '.fields' I get back a JSON array as follows: [{"name":"id","type":"int","doc":"Documentation for the id field."},{"name":"test_string","type":"string","doc":"Documentation for the test_string field"}] My goal is to do a call with jq applied to return the following (given the example above): {"id":1234567890,"test_string":"xxxxxxxxxx"} NB: I am