jq

How can I duplicate an existing object within a JSON array using jq?

戏子无情 提交于 2021-02-20 19:17:12
问题 I have the following geojson file: { "type": "FeatureCollection", "features": [{ "type": "Feature", "properties": { "LINE": "RED", "STATION": "Harvard" }, "geometry": { "type": "Point", "coordinates": [-71.118906072378209, 42.37402923068516] } }, { "type": "Feature", "properties": { "LINE": "RED", "STATION": "Ashmont" }, "geometry": { "type": "Point", "coordinates": [-71.063430144389983, 42.283883546225319] } } ] } I would like to append the second object within the "features" array to the

How can I duplicate an existing object within a JSON array using jq?

痞子三分冷 提交于 2021-02-20 19:16:55
问题 I have the following geojson file: { "type": "FeatureCollection", "features": [{ "type": "Feature", "properties": { "LINE": "RED", "STATION": "Harvard" }, "geometry": { "type": "Point", "coordinates": [-71.118906072378209, 42.37402923068516] } }, { "type": "Feature", "properties": { "LINE": "RED", "STATION": "Ashmont" }, "geometry": { "type": "Point", "coordinates": [-71.063430144389983, 42.283883546225319] } } ] } I would like to append the second object within the "features" array to the

JQ, Hadoop: taking command from a file

房东的猫 提交于 2021-02-19 08:33:00
问题 I have been enjoying the powerful filters provided by JQ (Doc). Twitter's public API gives nicely formatted json files. I have access to a large amount of it, and I have access to a Hadoop cluster. There I decided to, instead of loading them in Pig using Elephantbird , try out JQ in mapper streaming to see if it is any faster. Here is my final query: nohup hadoop jar $HADOOP_HOME/share/hadoop/tools/lib/hadoop-streaming-2.5.1.jar\ -files $HOME/bin/jq \ -D mapreduce.map.memory.mb=2048\ -D

JQ, Hadoop: taking command from a file

Deadly 提交于 2021-02-19 08:32:21
问题 I have been enjoying the powerful filters provided by JQ (Doc). Twitter's public API gives nicely formatted json files. I have access to a large amount of it, and I have access to a Hadoop cluster. There I decided to, instead of loading them in Pig using Elephantbird , try out JQ in mapper streaming to see if it is any faster. Here is my final query: nohup hadoop jar $HADOOP_HOME/share/hadoop/tools/lib/hadoop-streaming-2.5.1.jar\ -files $HOME/bin/jq \ -D mapreduce.map.memory.mb=2048\ -D

How to check for null or empty in jq and substitute for empty string in jq transformation

匆匆过客 提交于 2021-02-19 07:47:06
问题 How to check for null or empty in jq and substitute for empty string in jq transformation. Example in below JSON, this is the JQ JQ: .amazon.items[] | select(.name | contains ("shoes")) as $item | { activeItem: .amazon.activeitem, item : { id : $item.id, state : $item.state, status : if [[ $item.status = "" or $item.status = null ]]; then 'IN PROCESS' ; else $item.status end } } JSON: { "amazon": { "activeitem": 2, "items": [ { "id": 1, "name": "harry potter", "state": "sold" }, { "id": 2,

Convert JSON to CSV with jq

懵懂的女人 提交于 2021-02-19 05:50:08
问题 I'm trying to extract the sids, ll, state, name, smry values in my JSON file using jq and export to a csv. JSON File (out.json): { "data": [ { "meta": { "uid": 74529, "ll": [ -66.9333, 47.0667 ], "sids": [ "CA008102500 6" ], "state": "NB", "elev": 1250, "name": "LONG LAKE" }, "smry": [ [ "42", "1955-02-23" ] ] }, { "meta": { "uid": 74534, "ll": [ -67.2333, 45.9667 ], "sids": [ "CA008103425 6" ], "state": "NB", "elev": 150.9, "name": "NACKAWIC" }, "smry": [ [ "40", "1969-02-23" ] ] }, { "meta"

Create JSON file using jq

不羁岁月 提交于 2021-02-18 21:12:14
问题 I'm trying to create a JSON file by executing the following command: jq --arg greeting world '{"hello":"$greeting"}' > file.json This command stuck without any input. While jq -n --arg greeting world '{"hello":"$greeting"}' > file.json doesn't parse correctly. I'm just wondering is really possible to create a JSON file. 回答1: So your code doesn't work because included the variable inside double quotes which gets treated as string. That is why it is not working As @Jeff Mercado, pointed out the

javascript之闭包,递归,深拷贝

笑着哭i 提交于 2021-02-18 14:23:26
闭包 理解: a 函数执行后 return 出 b 函数且 b 函数可以访问 a 函数的数据 好处:子函数存储在复函数内部,子函数执行完不会被自动销毁 坏处:占用内存比较大 ex: function bibao(){ var i=10 ; return function (){ console.log(i); return i++ ; } } var bibao_task= bibao(); bibao_task(); bibao_task(); bibao_task(); 递归 理解:子元素有子元素,子元素的子元素有子元素 ..... 深拷贝和浅拷贝 理解:人的克隆和影子的区别,内存地址的区别 深拷贝: Json 函数 Target=JSON.parse(JSON.stringify(obj)) Jq 的 $.extend $.extend( true ,target,obj)//参数为true为深拷贝,否则为浅拷贝 递归深拷贝 var china = { nation : '中国' , birthplaces:{ name: 'chen' } } // 深复制,要想达到深复制就需要用递归 var newc= {}; function copy(china,newc){ for (i in china){ if ( typeof china[i]==='object' ){

Turning JSON blob into BQ friendly format with JQ

久未见 提交于 2021-02-16 21:25:09
问题 To be upfront, I have next to no experience with JSON, JQ, or much of anything on the Java side. I've been spending a lot of time trying to use the jq command line function to properly format a test blob of data in a way that I can easily feed into Google BigQuery. { "total_items": 848, "page_count": 34, "items": [ { "landing_id": "708d9e3eb106820f98162d879198774b", "token": "708d9e3eb106820f98162d879198774b", "response_id": "708d9e3eb106820f98162d879198774b", "landed_at": "2019-02-12T01:58

Turning JSON blob into BQ friendly format with JQ

我只是一个虾纸丫 提交于 2021-02-16 21:24:15
问题 To be upfront, I have next to no experience with JSON, JQ, or much of anything on the Java side. I've been spending a lot of time trying to use the jq command line function to properly format a test blob of data in a way that I can easily feed into Google BigQuery. { "total_items": 848, "page_count": 34, "items": [ { "landing_id": "708d9e3eb106820f98162d879198774b", "token": "708d9e3eb106820f98162d879198774b", "response_id": "708d9e3eb106820f98162d879198774b", "landed_at": "2019-02-12T01:58