jq

Concat 2 fields in JSON using jq

隐身守侯 提交于 2020-05-24 16:44:09
问题 I am using jq to reformat my JSON . JSON String: {"channel": "youtube", "profile_type": "video", "member_key": "hello"} Wanted output: {"channel" : "profile_type.youtube"} My command: echo '{"channel": "youtube", "profile_type": "video", "member_key": "hello"}' | jq -c '. | {channel: .profile_type + "." + .member_key}' I know that the command below concatenates the string. But it is not working in the same logic as above: echo '{"channel": "youtube", "profile_type": "video", "member_key":

Exclude object if sub array contains n occurrences of a string with jq

寵の児 提交于 2020-05-16 05:46:11
问题 I have this [ { "title": "foo", "label": [ "bar-one", "bare-two" ] }, { "title": "foo_42", "label": [ "bar-one", "bare-two" ] }, { "title": "foo_42", "label": [ "bar-one" ] } ] I want to count the occurrences of "bar" in array label then exclude object if count > 1 (can be in 2part) ex after process: [ { "title": "foo_42", "label": [ "bar-one" ] } ] I try different solutions, based on How to select items in JQ based on value in array and https://github.com/stedolan/jq/issues/861 but I can't

Exclude object if sub array contains n occurrences of a string with jq

眉间皱痕 提交于 2020-05-16 05:45:07
问题 I have this [ { "title": "foo", "label": [ "bar-one", "bare-two" ] }, { "title": "foo_42", "label": [ "bar-one", "bare-two" ] }, { "title": "foo_42", "label": [ "bar-one" ] } ] I want to count the occurrences of "bar" in array label then exclude object if count > 1 (can be in 2part) ex after process: [ { "title": "foo_42", "label": [ "bar-one" ] } ] I try different solutions, based on How to select items in JQ based on value in array and https://github.com/stedolan/jq/issues/861 but I can't

Merge two arrays into a single object with jq

我只是一个虾纸丫 提交于 2020-05-13 18:56:27
问题 I'm trying to use jq to parse a NOAA data feed into just the values I need: http://forecast.weather.gov/MapClick.php?FcstType=json&lat=39.56&lon=-104.85 I'm able to (separately) extract the two arrays I'm looking to combine: $ cat noaa.json | jq .time.startPeriodName [ "Today", "Tonight", "Friday", "Friday Night", "Saturday", "Saturday Night", "Sunday", "Sunday Night", "Monday", "Monday Night", "Tuesday", "Tuesday Night", "Wednesday" ] $ cat noaa.json | jq .data.weather [ "Mostly Sunny",

Merge two arrays into a single object with jq

我的梦境 提交于 2020-05-13 18:56:06
问题 I'm trying to use jq to parse a NOAA data feed into just the values I need: http://forecast.weather.gov/MapClick.php?FcstType=json&lat=39.56&lon=-104.85 I'm able to (separately) extract the two arrays I'm looking to combine: $ cat noaa.json | jq .time.startPeriodName [ "Today", "Tonight", "Friday", "Friday Night", "Saturday", "Saturday Night", "Sunday", "Sunday Night", "Monday", "Monday Night", "Tuesday", "Tuesday Night", "Wednesday" ] $ cat noaa.json | jq .data.weather [ "Mostly Sunny",

How to install JQ on Mac by command-line?

 ̄綄美尐妖づ 提交于 2020-05-09 18:37:08
问题 I need to know the most efficient way of installing JQ on Mac (el capitan). The code is downloaded to my mac but I would like to know how I can install and operate the via the command line. 回答1: You can install any application/packages with brew on mac. If you want to know the exact command just search your package on https://brewinstall.org and you will get the set of commands needed to install that package. First open terminal and install brew ruby -e "$(curl -fsSL https://raw

移动端创意导航

大憨熊 提交于 2020-05-09 15:54:37
效果图 index.html <! DOCTYPE html > < html lang ="en" > < head > < meta charset ="UTF-8" > < title > index </ title > < link rel ="stylesheet" href ="css/reset.css" > < link rel ="stylesheet" href ="css/style.css" > </ head > < body > < div class ="screen" > < nav class ="nav" > < ul > < li >< a href ="#" > 搜 索 </ a ></ li > < li >< a href ="#" > 主 页 </ a ></ li > < li >< a href ="#" > HTML5学习 </ a ></ li > < li >< a href ="#" > CSS3学习 </ a ></ li > < li >< a href ="#" > 联系我们 </ a ></ li > </ ul > </ nav > < div class ="nav-toggle" > < div class ="icon" ></ div > </ div > <!-- 背景内容区 --> < div

Convert text file with key=value pair to specific json format in jq

白昼怎懂夜的黑 提交于 2020-05-09 09:45:26
问题 I have a text file with following values in input.txt key1=value1\r key2=value2 key3=value3\r key4=value4 need the jq rexpression to convert it to below json format by removing "\r" also output.json { "Environment": { "Variables": { "key1": "value1", "key2": "value2", "key3": "value3", "key4": "value4" } } } I have tried the below expression and getting the jq -Rs [ split("\n")[] | select(length > 0) | split("=") | {(.[0]): .[1]} ] and getting the below output [ { "key1ey1": "Value1\r" }, {

Convert text file with key=value pair to specific json format in jq

倖福魔咒の 提交于 2020-05-09 09:44:07
问题 I have a text file with following values in input.txt key1=value1\r key2=value2 key3=value3\r key4=value4 need the jq rexpression to convert it to below json format by removing "\r" also output.json { "Environment": { "Variables": { "key1": "value1", "key2": "value2", "key3": "value3", "key4": "value4" } } } I have tried the below expression and getting the jq -Rs [ split("\n")[] | select(length > 0) | split("=") | {(.[0]): .[1]} ] and getting the below output [ { "key1ey1": "Value1\r" }, {

主动触发事件 自定义事件 trigger 及其用法

妖精的绣舞 提交于 2020-05-09 06:29:46
1. 触发自定义事件方式 js、jq 2. jq 触发 2.1 默认支持的事件 $('#h').on('click',function(){ $(this).append('<p>p</p>') }) $('#h').trigger('click'); $('#h').click(); 2.2 自定义事件 $('#h').on('myclick',function(){ $(this).append('<p>p</p>') }) $('#h').trigger('myclick'); 3. js 触发 // 首先需要提前定义好事件,并且注册相关的EventListener var myEvent = new CustomEvent('event_name' , { detail: { title: 'This is title!' }, }); window.addEventListener( 'event_name', function (event) { console.log( '得到标题为:' , event.detail.title); }); // 随后在对应的元素上触发该事件 setInterval( function () { if (window.dispatchEvent) { window.dispatchEvent(myEvent); } else {