jq

Select multiple fields at different levels

[亡魂溺海] 提交于 2021-02-16 20:51:30
问题 I've a .json file that look like : [ { "network": "X.X.X.1", "defaultGateway": "X.X.X.X", "ipAddressTab": [ { "foo1": "10.0.0.1", "foo2": "network", "foo3": "reserved", "foo4": null, "foo5": null, "foo6": null, "foo7": null, "foo8": null, "foo9": null, "foo10": null, "foo11": null }, { "foo1": "10.0.0.2", "foo2": "network", "foo3": "reserved", "foo4": null, "foo5": null, "foo6": null, "foo7": null, "foo8": null, "foo9": null, "foo10": null, "foo11": null }, { "foo1": "10.0.0.3", "foo2":

jq: How to output quotes on raw output on windows

非 Y 不嫁゛ 提交于 2021-02-16 18:02:33
问题 Using raw output I have to quote some values of the output. echo [{"a" : "b"}] | jq-win64.exe --raw-output ".[] | \"Result is: \" + .a + \".\"" generates Result is: b. but how can I generate Result is: "b". Unfortunately it has to run on Windows called from inside a CMD file. 回答1: You need to escape the slashes to escape a " $ echo [{"a" : "b"}] | jq-win64.exe --raw-output ".[] | \"Result is: \\\"\" + .a + \"\\\".\"" Result is: "b". 回答2: A hacky workaround with less backslashing could be: jq

How can I put integer as an argument in jq?

人盡茶涼 提交于 2021-02-16 16:14:30
问题 I have been trying to use jq to parse a json file returned from the aws cli, but I'm stuck with the problem of referencing an array using the index number. I need to do this because I want to export a text file describing the security groups in a specific format, including all the inbound and outbound rules. for (( i=1; i<=groupCount; i++ )) ; do echo $i echo $(echo "$input" | jq --arg i $i '.SecurityGroups[$i]') done This returns an error: 1 jq: error (at <stdin>:189): Cannot index array

How to keep one level of object and extract one of its sub-key only?

老子叫甜甜 提交于 2021-02-16 14:58:05
问题 I'm playing a bit with terraform state json output and want to transform it a bit. Given that input issued from terraform: { "cost": { "sensitive": false, "value": "123" }, "test_id": { "sensitive": false, "value": "6610758455459338306" } } How do i convert it to something usefull for my application like bellow: { "cost": "123", "test_id": "6610758455459338306" } I tried to play with from_entries , with_entries but i'm a complete noob at it 回答1: You're looking for map_values. It works just

thinkjs升级到3.0后的图片上传

岁酱吖の 提交于 2021-02-14 15:28:16
似乎当thinkjs升级到3.0后,才接手了一个项目。只是在实际运用过程中,还是发现了与2.2的些许差别——今天先分享关于图片上传的一些问题。 1.上传文件,我们选择了jQuery的插件: http://www.jq22.com/jquery-info230 屡试不爽,各种好评。只是后来项目上线的时候,才发现保存在数据库的img都没有后缀名…… 这是什么情况。。。。。。原谅自己没仔细看数据库存的方式,只是从表面看见图片可以显示了就随意了,结果导致后来又坑了自己。检查了很久,还是从自身找问题吧,翻看thinkjs文档,有什么差距呢? 给接口的文件路径中缺少后缀名,导致接口返回过来的文件也就缺少了后缀! 那合理的解决办法呢? 1.接口修改一下方法?No,他们说这是一个公共方法,不能因为一个项目而更改接口; 2.我来修改方法,将完整的图片路径传给接口然后就ok了。 1.后台上传方法js: 1 async uploadAction() { 2 if (!think.isEmpty( this .file('uploadFile' ))) { 3 // 进行压缩等处理 4 let file = think.extend({}, this .file('uploadFile' )); 5 6 // 保存文件的路径 7 let savepath =think.ROOT_PATH + '/www

百度地图JS-API:点击地图获取经纬度

断了今生、忘了曾经 提交于 2021-02-14 06:12:07
1.引用百度地图引用js <%--这是百度的js--%> < script type ="text/javascript" src ="http://api.map.baidu.com/api?v=3.0&ak=这里是填写你在百度地图申请的秘钥,不是这串文字" ></ script > <%--这是引用个jq--%> <script type="text/javascript" src="jquery.min.js"></script> 2.创建input和div <!-- 这是地图的div --> < div id ="allmap" style ="width: 100%;height: 450px;" ></ div > <!-- 这是地址详情框 --> < input type ="text" id ="site" > <!-- 这是 经度 --> < input type ="text" id ="longitude" > <!-- 这是 维度 --> < input type ="text" id ="latitude" > 3.写功能js < script > // 百度地图API功能 var map = new BMap.Map( " allmap " ); var point = new BMap.Point(107.31612162513613,30

why does jq print records redundantly and mismatched and how to fix it?

拟墨画扇 提交于 2021-02-11 16:26:49
问题 I have a file of json that includes six 'invoice' object, each object is 140+ lines of values. I want to see only a few values for each of the six objects. jq seemed like a promising solution. I'm using jq version 1.5-1-a5b5cbe which was available via apt 's usual repositories. I can do cat stripe-invoices-list.json | jq -C '. | {invoice_id: .data[].id,}' and it returns: { "invoice_id": "in_1Gq39HFGUwFHXzvlUOGG3Rv4" } { "invoice_id": "in_1GpyM1FGUwFHXzvlio9pfaM9" } { "invoice_id": "in

JQ, convert CSV (parent child format) to JSON

本秂侑毒 提交于 2021-02-11 12:52:30
问题 I have a CSV file (parent child format). Is it possible to convert to JSON format by using JQ ? CSV file <pre> id parent_id text 1 NULL engine 2 1 exhaust 3 1 cooling 4 3 cooling fan 5 3 water pump 6 NULL frame 7 6 wheels 8 6 brakes 9 8 brake calipers 10 6 cables </Pre> JSON file <Pre> [ { "id": "1", "text": "engine", "children": [ { "id": "2", "text": "exhaust", "children": [] }, { "id": "3", "text": "cooling", "children": [ { "id": "4", "text": "cooling fan", "children": [] }, { "id": "5",

how to select a json object where a child value array contains a certain propery

给你一囗甜甜゛ 提交于 2021-02-11 07:38:59
问题 I have an array of objects similar to the following: [ { "id": "one", "tags": { "my.key": "true" } }, { "id": "two", } ] How can I select all "id" values for each object containing a tag where "my.key" is "true"? 回答1: You can use a select with .tags["my.key"] == "true" and get only the id field : jq '.[] | select(.tags["my.key"] == "true") | .id' data.json 来源: https://stackoverflow.com/questions/41369982/how-to-select-a-json-object-where-a-child-value-array-contains-a-certain-propery

Json to CSV issues

拜拜、爱过 提交于 2021-02-11 02:49:13
问题 I am using pandas to normalize some json data. I am getting stuck on this issue when more than 1 section is either an object or an array. If i use the record_path on Car it breaks on the second. Any pointers on how to get something like this to create a line in the csv per Car and per Location? [ { "Name": "John Doe", "Car": [ "Car1", "Car2" ], "Location": "Texas" }, { "Name": "Jane Roe", "Car": "Car1", "Location": [ "Illinois", "Kansas" ] } ] Here is the output Name,Car,Location John Doe,"[