Passing bash variable to jq

I have written a script to retrieve certain value from file.json. It works if I provide the value to jq select, but the variable doesn’t seem to work (or I don’t know how to use it). #!/bin/sh #this works *** projectID=$(cat file.json | jq -r ‘.resource[] | select(.username==”[email protected]”) | .id’) echo “$projectID” [email protected] #this does … Read more

How to merge 2 JSON objects from 2 files using jq?

I’m using the jq tools (jq-json-processor) in shell script to parse json. I’ve got 2 json files and want to merge them into one unique file Here the content of files: file1 { “value1”: 200, “timestamp”: 1382461861, “value”: { “aaa”: { “value1”: “v1”, “value2”: “v2” }, “bbb”: { “value1”: “v1”, “value2”: “v2” }, “ccc”: { … Read more

JWT vs cookies for token-based authentication

I read some posts about “JWT vs Cookie” but they only made me more confused… I want some clarification, when people talking about “token-based authentication vs cookies”, cookies here merely refer to session cookies? My understanding is that cookie is like a medium, it can be used to implement a token-based authentication(store something that can … Read more

Mongoimport of JSON file

I have a JSON file consisting of about 2000 records. Each record which will correspond to a document in the mongo database is formatted as follows: {jobID:”2597401″, account:”XXXXX”, user:”YYYYY”, pkgT:{“pgi/7.2-5”:{libA:[“libpgc.so”],flavor:[“default”]}}, startEpoch:”1338497979″, runTime:”1022″, execType:”user:binary”, exec:”/share/home/01482/XXXXX/appker/ranger/NPB3.3.1/NPB3.3-MPI/bin/ft.D.64″, numNodes:”4″, sha1:”5a79879235aa31b6a46e73b43879428e2a175db5″, execEpoch:1336766742, execModify: new Date(“Fri May 11 15:05:42 2012”), startTime: new Date(“Thu May 31 15:59:39 2012″), numCores:”64″, sizeT:{bss:”1881400168″,text:”239574″,data:”22504”}}, Each record … Read more

Check if a Postgres JSON array contains a string

I have a table to store information about my rabbits. It looks like this: create table rabbits (rabbit_id bigserial primary key, info json not null); insert into rabbits (info) values (‘{“name”:”Henry”, “food”:[“lettuce”,”carrots”]}’), (‘{“name”:”Herald”,”food”:[“carrots”,”zucchini”]}’), (‘{“name”:”Helen”, “food”:[“lettuce”,”cheese”]}’); How should I find the rabbits who like carrots? I came up with this: select info->>’name’ from rabbits where exists … Read more