jq

pair values from different levels selecting one based on neighbor member

爷,独闯天下 提交于 2021-01-29 12:21:51
问题 I'm trying to go through an array of objects w/ jq and convert that to csv. I can do the some of the selection and to csv part but what I'm struggling with is figuring out how to get the Name tag value of each object. The json looks like this: { "Groups": [], "Instances": [ { "InstanceType": "m5.xlarge", "Tags": [ { "Key": "jenkins_slave_type", "Value": "demand_ec2 small" }, { "Key": "color", "Value": "jenkins" }, { "Key": "role", "Value": "jenkins" }, { "Key": "stack", "Value": "dev-us-east

How do I use a value as a key reference in jq?

筅森魡賤 提交于 2021-01-29 11:44:31
问题 I have two JSON files as follows. One contains a mapping of project to owners. owners.json { "Project1": "owner1", "Project2": "owner2" } The second contains a list of projects with extra information: projects.json [ { "name": "Project1", "base": "A" }, { "name": "Project2", "base": "B" } ] I'd like to use JQ to merge the two files to look like the following: output.json [ { "name": "Project1", "owner": "owner1", "base": "A" }, { "name": "Project2", "owner": "owner2", "base": "B" } ] My first

Vue3对于一个前端来讲意味着什么?

匆匆过客 提交于 2021-01-29 09:48:52
// 且读且珍惜 // 正文字数 1828 最近很多微信公众号和技术社区,讨论的最多的无非就是 Vue3 了,大多数都是Composition API和基于Proxy的它的原理分析。但是今天老袁想着跟大家聊聊,Vue3对于一个前端更深层次的意义到底意味着什么?我们从这个几个方面来聊聊吧。 悠悠十年,前端框架催人老 理性追框架 Vue的原理的原理了解一下 珍惜年轻的日子 未来可期 悠悠十年,前端框架催人老 相信很多老前端,可能跟我一样。以前天天要兼容IE6、7、8、9、10、11、12+还有一大堆什么你根本叫不上来名字的浏览器,那时候就盼着啥时候有一天能不再兼容这鬼玩意,嗯。到了今天,我们当初心心念念的时代来了,我们再也不用为了CSS而付出太多的努力。虽然依然存在一些不兼容,但是我们可以使用CSS的工作流可以使用PostCSS,甚至直接使用Houdini去介入到浏览器的重绘和重排。那时候我们使用jQuery对浏览器事件的大兼容,更不用搞什么啥babel-polyfill。有人可能会说jq那玩意多恶心啊,谁用啊。其实这东西看怎么写了,写好了其实没那么恶心。不过在今天,大家美滋滋的写着TS的时候,大部分同学其实也未曾关注过所谓编译之后的东西长什么样,其实也挺🤢 Knockout 的横空出世突然让我们觉得手里的jq代码不香了,大家第一次体会到了MVVM的快乐

Convert json array with values only to csv using jq

帅比萌擦擦* 提交于 2021-01-29 08:24:20
问题 I have a below JSON and I need to convert it to a CSV. The problem I'm having is that those values have no key. Ideally I would like CSV to look like this, I just don't know how to do it using jq. CSV year;points;surname;name;point1;points2;points3;city;district;url 2020;54;Smith;John;;;London;Waterloo;URL 2015;380;Helen;Smith;;;New York;Manhattan;URL JSON { "draw": 0, "total": "44", "filtered": "8", "data": [ [ "2020", "54", "Smith ", "John", "", "", "", "London", "Waterloo", "URL" ], [

python api response to json object

倾然丶 夕夏残阳落幕 提交于 2021-01-29 05:06:00
问题 I am trying to write a script to parse over an api response using jq. I can get it to work using bash and the cli, but i want to script it in python so i can put a lot more logic into it. The problem i am having is that i can get the api response but when i try load it using the json.loads() or json.dump() i keep getting the following error: TypeError: the JSON object must be str, bytes or bytearray, not APIResponse Here is the response i get from the api APIResponse({ "data": { "color": "red

Get last N elements for each item of a JSON object

送分小仙女□ 提交于 2021-01-29 04:43:20
问题 Given the following JSON object, using jq, how to get the last two elements for each item? I have been trying to find a solution with the help of jqplay.org but didn't get anywhere. While getting values out of objects having consistent key names is rather straightforward, I can't get my head around this. Input: { "foo": { "abc": { "key1": "value1" }, "bcd": { "key1": "value1" }, "cde": { "key1": "value1" }, "def": { "key1": "value1" }, "efg": { "key1": "value1" }, "fgh": { "key1": "value1" }

read raw input lines and output single array

允我心安 提交于 2021-01-28 23:59:13
问题 I have a directory with files in it. I would like to create an array from that list of files. I thought it would be pretty easy, like: ls mydir | jq -R '[.]' [ "file1" ] [ "file2" ] [ "file3" ] The only thing I could figure out is this: ls mydir | jq -sR '[split("\n")[]|select(.|length>0)]' [ "file1", "file2", "file3" ] Is there a better way? 回答1: You'd have to be extra careful in dealing with Unix filenames in general. They can contain almost any character in a filename, including whitespace

read raw input lines and output single array

China☆狼群 提交于 2021-01-28 23:46:46
问题 I have a directory with files in it. I would like to create an array from that list of files. I thought it would be pretty easy, like: ls mydir | jq -R '[.]' [ "file1" ] [ "file2" ] [ "file3" ] The only thing I could figure out is this: ls mydir | jq -sR '[split("\n")[]|select(.|length>0)]' [ "file1", "file2", "file3" ] Is there a better way? 回答1: You'd have to be extra careful in dealing with Unix filenames in general. They can contain almost any character in a filename, including whitespace

read raw input lines and output single array

此生再无相见时 提交于 2021-01-28 22:40:05
问题 I have a directory with files in it. I would like to create an array from that list of files. I thought it would be pretty easy, like: ls mydir | jq -R '[.]' [ "file1" ] [ "file2" ] [ "file3" ] The only thing I could figure out is this: ls mydir | jq -sR '[split("\n")[]|select(.|length>0)]' [ "file1", "file2", "file3" ] Is there a better way? 回答1: You'd have to be extra careful in dealing with Unix filenames in general. They can contain almost any character in a filename, including whitespace