jq

Generating a JSON map containing shell variables named in a list

有些话、适合烂在心里 提交于 2020-02-04 06:33:29
问题 My shell-fu is at a below-beginner level. I have a file that contains some lines that happen to be the names of environment variables. e.g. ENV_VAR_A ENV_VAR_B ... What I want to do is use this file to generate a JSON string containing the names and current values of the named variables using jq like this: jq -n --arg arg1 "$ENV_VAR_A" --arg arg2 "$ENV_VAR_B" '{ENV_VAR_A:$arg1,ENV_VAR_B:$arg2}' # if ENV_VAR_A=one and ENV_VAR_B=two then the preceding command would output # {"ENV_VAR_A":"one",

JQurey的基本使用

╄→尐↘猪︶ㄣ 提交于 2020-01-31 09:45:32
使用jquery, 必须先引入jq库 < script src = "jquery-3.4.1.min.js" > < / script > js的变量 var a = 10 ; jq的变量 var $a = 10 ; // $ 声明该变量是jq变量 同时$也是JQuery的简写 dom的变量 和 jq的变量之间 转换 转换为jq变量 var oDiv = document . getElementsByClassName ( "box" ) [ 0 ] ; var $b = $ ( oDiv ) ; console . log ( $b ) ; 转换为DOM变量 var $c = $b [ 0 ] ; console . log ( $c ) ; jq中 顶级对象 是 $ 或者jQuery关键字 注意: jQuery中的 $ 和 jQuery关键字 本身同为一个对象 js中的入口函数: window.onload jq中的入口函数: $(document).ready(function(){…}); onload和 ready的区别: 文档的加载步骤: 1. 解析HTML结构 2. 加载外部的样式表和脚本 3. 解析并执行脚本 4. 构建HTML–DOM模型 (ready方法执行) 5. 加载图片等外部资源 6. 页面加载完毕 (load方法执行) $ ( document )

jq——选择器

ぐ巨炮叔叔 提交于 2020-01-31 05:41:22
jquery:核心,内容 语法:$(select).action(); console.log:控制台日志,将想要的东西打印出来 选择器,事件,DOM,动画,基本操作,插件,ajax 基本选择器 #id:id选择器:$("#id名") element:元素选择器 class:类选择器 selector选择器:将每一个选择器匹配到的元素合并后一起返回 层级选择器 ancestor descendant:表示选取ancestor里面的所有的descendant元素 parent>child:选择parent元素为子元素 +selecter:获取后面一个兄弟 selecter~:获取后面所有兄弟 内容选择器 :contains("text"):匹配含有text内容的元素 :empty:匹配内容为空的元素 :has(selecter):选择包含有selecter的选择器 :parent:选择作为父元素的元素:$("p:parent").css({background:"red"}); $("div:parent").hide(6000);缓慢隐藏 $("div:parent").show(6000);缓慢出现 元素的基本选择器 1 :first:查找第一个子元素 <script type="text/javascript"> $("input").click(function() { $(

JQ argument error in bash script

荒凉一梦 提交于 2020-01-30 12:28:06
问题 I have a problem with a JQ query: max=$(script) <-- (return integer) jq -r ".notifiestext | map(select(.read==false))" temp_notif | jq --arg foo "$max" "map(select(.id<$foo))" I get the following error: jq: error: syntax error, unexpected ')' (Unix shell quoting issues?) at <top-level>, line 1: map(select(.id<)) The ".id" parameter is an integer Any solution? 回答1: You need to escape the $ for $foo so that the shell doesn't try to expand it as a parameter before jq even runs. jq -r "

jq not replacing json value with parameter

梦想的初衷 提交于 2020-01-30 05:21:45
问题 test.sh is not replacing test.json parameter values ($input1 and $input2). result.json has same ParameterValue "$input1/solution/$input2.result" [ { "ParameterKey": "Project", "ParameterValue": [ "$input1/solution/$input2.result" ] } ] test.sh #!/bin/bash input1="test1" input2="test2" echo $input1 echo $input2 cat test.json | jq 'map(if .ParameterKey == "Project" then . + {"ParameterValue" : "$input1/solution/$input2.result" } else . end )' > result.json 回答1: shell variables in jq scripts

Complex jq Filter

怎甘沉沦 提交于 2020-01-29 17:46:12
问题 Disclaimer: this is not homework, this is a sanitized version of something I'm doing for work. I'm trying to filter some json data using jq and want to return an object for each matching record in my filter. Here's a text description of what I'm doing: "Given a JSON object containing a list of students, some personal info, and their grades, return a list of the name, ages, and cumulative gpa for each student that received an A in CSC101." Here's the test JSON object (program input): {

Complex jq Filter

亡梦爱人 提交于 2020-01-29 17:45:48
问题 Disclaimer: this is not homework, this is a sanitized version of something I'm doing for work. I'm trying to filter some json data using jq and want to return an object for each matching record in my filter. Here's a text description of what I'm doing: "Given a JSON object containing a list of students, some personal info, and their grades, return a list of the name, ages, and cumulative gpa for each student that received an A in CSC101." Here's the test JSON object (program input): {

Complex jq Filter

只谈情不闲聊 提交于 2020-01-29 17:45:03
问题 Disclaimer: this is not homework, this is a sanitized version of something I'm doing for work. I'm trying to filter some json data using jq and want to return an object for each matching record in my filter. Here's a text description of what I'm doing: "Given a JSON object containing a list of students, some personal info, and their grades, return a list of the name, ages, and cumulative gpa for each student that received an A in CSC101." Here's the test JSON object (program input): {

jq事件冒泡的区别

痞子三分冷 提交于 2020-01-26 23:48:13
1.event.stopPropagation(); 事件处理过程中,阻止了事件冒泡,但不会阻击默认行为(它就执行了超链接的跳转) 2.return false; 事件处理过程中,阻止了事件冒泡,也阻止了默认行为(比如刚才它就没有执行超链接的跳转) 还有一种有冒泡有关的: 3.event.preventDefault(); 如果把它放在头部A标签的click事件中,点击“点击我”。 会发现它依次弹出:我是最里层---->我是中间层---->我是最外层,但最后却没有跳转到百度 它的作用是:事件处理过程中,不阻击事件冒泡,但阻击默认行为(它只执行所有弹框,却没有执行超链接跳转) 来源: https://www.cnblogs.com/theArrow/p/7895139.html

JQ——遍历(each遍历、数组遍历)、添加(append、appendTo)

 ̄綄美尐妖づ 提交于 2020-01-26 20:56:53
1、each实现遍历操作: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>each实现的遍历</title> <script type="text/javascript" src="../js/jquery-1.8.3.js" ></script> <script> $(function(){ $("button").click(function(){ $("li").each(function(){ alert($(this).text()) }); }); }); </script> </head> <body> <button>点击按键,each实现遍历操作</button> <ul> <li>2020</li> <li>新年好!</li> <li>武汉加油!</li> </ul> </body> </html> 2、遍历数组: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>数组遍历</title> <script type="text/javascript" src="../js/jquery-1.8.3.js" ></script> <script> $(function () { $.each([213,37,34,567