Questions tagged [json]

JSON (JavaScript Object Notation) is a lightweight data representation format that resembles JavaScript source and that is can be easily red by machines and edited by humans with some effort.

Filter by
Sorted by
Tagged with
5
votes
5answers
7k views

looping through JSON array in shell script

Below is the curl command output (file information about branch), need script or command to print file name, filetype and size. I have tried with jq but was able fetch single value ( jq '.values[]....
0
votes
1answer
2k views

How to merge json files using jq or any tool?

Modifying the question to be more specific. There will be 2 JSON files where first one will have few blocks. And second one will have few blocks with few addition of redirection rules as you can see "...
7
votes
3answers
4k views

How to find and replace multiple field values using jq?

In the following json file, { "email": "xxx", "pass": "yyy", "contact": [ { "id": 111, "name": "AAA" } ], "lname": "YYY", "name": "AAA", "group": [ { "...
0
votes
1answer
217 views

How to find a particular key and replace the value in shell script?

I have a JSON file with the following text {"category": "yyy", "id": "xxxyyy", "environment": "fff", "client": "000000", "user": "Alex", "log_time": "xxx", "source_context": null} I need to find ...
0
votes
3answers
136 views

sed command to replace and write

I am trying to replace the following string with another one from a file which contains few lines. "schema" : "AAAAA", TO "schema" : "BBBBB", Currently, I am doing the following command to get the ...
0
votes
2answers
121 views

How to parse json data using jq?

I need to fetch below objects from json which I am getting via API. I am trying with jq which is available on ubuntu 16.04. I am trying to get data in this format device_name C:| free 18707755008.0 ...
0
votes
2answers
121 views

How to swap two fields inside a JSON file

I have a file like this {"100":["0.00001","10","0.01"], "101":["0.0001","100","0.1"], "102":["1","1000","1"], .... "103":["0.01","10000","10"]} I want to swap the second number with the third, ...
0
votes
4answers
147 views

jq and awk for version file extraction

Using a JSON file with the following content: {"major":a, "minor":b, "hotfix":c} I'm trying to use jq to generate the following output: a.b.c I've used individual jq commands, such as jq .major ...
0
votes
3answers
526 views

How to parse JSON with shell scripting for braces edge case

I have a JSON output from which I need to extract a few parameters in Linux. This is the JSON output: { items:[ { provider_name:"ucp-ipg", subject_name:"rtm-instrumentation", ...
0
votes
0answers
168 views

LogStash Json ParserError

I need to send a log with JSON format from rsyslog to logsatsh and then from logstash to graylog. All the steps I have done. step 1 : config /etc/rsyslog.conf *.* action(type="omfwd" target="192....
1
vote
3answers
486 views

bash: assign variable and print to stdout in same command [closed]

I'm working on a bash script that reads a csv file with fields and field values and creates a json string out of the input. For simplicity I have a bash script that takes in two arguments simulating ...
1
vote
1answer
772 views

jq print value of an element where a key array is empty or a key is missing

{ "vehicle": [ { "type": "car", "features": [ { "airbags": "yes", "engine": [ { ...
1
vote
2answers
475 views

Find file json check if generated or execute

I want to find *.json2 files , check if they r executed if no execute POST. I have 1.json2 2.json2 2.json2.ml 3.json2 3.json2.ml I use this command find . -type f -name '*.json2' | if [{}.ml];...
-1
votes
1answer
49 views

Minimized JSON code between two patterns with regex

Let's take a file with for example : "test": [ { } ], "test": [ ...
3
votes
1answer
221 views

Create a JSON file of all installed dpkg software

I'm trying to collect all packages installed through dpkg in a JSON file. I tried this script: echo [ > installed_packages.json dpkg-query -W -f '{"name":"${binary:Package}","version":"${Version}"...
1
vote
2answers
246 views

How to parse with Bash script? (platform MIPS)? [duplicate]

$ curl -LNs "http://urladrescom/content.json" > content.json content.json { "k":[ { "i":1, "n":"NAME 1", "p":[ { "b":"Event 1", ...
7
votes
2answers
8k views

jq - add objects from file into json array

I want to add an array with elements and value into an existing json file using jq. I already have a file (input.json) with { "id": 9, "version": 0, "lastUpdTs": 1532371267968, "name": "...
0
votes
1answer
112 views

jq + capture the tag value

is it possible to capture the required tag value by jq for example we want to capture the tag value - version1531837630468 while the input is ams-env so jq will capture the tag value by ams-env { ...
0
votes
5answers
39 views

How to remove “” in output list?

I used a command to get a list of IP from EC2. The result so far i got is a list like this: [ "172.31.11.7", "172.31.48.141", "172.31.64.201", "172.31.64.149", "172.31.64.148", ...
2
votes
3answers
258 views

Generating unique IDs for json content indexing

I am looking for effective and simple ID generation for the following content using bash script: {"name": "John", "surname": "Gates", "country": "Germany", "age": "20", "height": "180"} {"name": "...
3
votes
1answer
438 views

Extract .json from a text file with arbitrary text

I have an output from a program that give some arbitrary text, with .json stuff inside like: blablablabla blablab some more text blablablabla blablab some more text { "glossary": { "...
5
votes
2answers
3k views

how to convert text file to json string (replace newlines with “\n”)

we have the following file : more value.js "\n#\n#\n# Licensed to the Apache Software Foundation (ASF) under one\n# or more contributor license agreements. See the NOTICE file\n# distributed with t ...
1
vote
1answer
4k views

jq + how to print only the value of key under properties

we have the follwing json file more t.json { "href" : "htr", "items" : [ { "href" : "lpo", "tag" : "version1533203561827110", "type" : "kafka-log4j", "version" : 6, ...
4
votes
5answers
20k views

How to retrieve values from json object using awk or sed [duplicate]

I have the following json [root@mdfdevha1 ~]# echo "$Group_ID" [ { "id" : "e27206c0-aeb6-43db-acda-c4ba43233071", "name" : "A1", "path" : "/A1", "subGroups" : [ ] }, { "id" : "89f3bd6a-...
1
vote
1answer
1k views

Regex to get single value from Json file using bash

I would like to retrieve a value "tenki-deploy-topic" from the below JSON file content. I used this regex grep -o 'topic[^"]*' output.log, then it gets all the files with the topic, instead, I want to ...
3
votes
1answer
870 views

Split a json array to multiple files

I have a file that looks like this: [ { "billingAccountNumber": "x", "paymentResponseObject": { "uiErrorDipslayMessage": "", "transactionStatus": "S", "...
1
vote
1answer
116 views

Two consecutive OPs after pipe or two jq OPs in one run?

I have to extract data from a slightly mis-formatted JSON string, hence I first pass it through sed & awk. What I have is a command like: `sed 's/},/},\n/g' test.json |awk '/"characater"/ { gsub("...
2
votes
3answers
314 views

extract data from JSON string

I've got to extract a license plate digit and it's associated confidence from a JSON string that looks like: { "response": { "container": { "id": "0df307bc-06b2-45cf-b7ff-ce07fd04e04d", ...
3
votes
4answers
697 views

Can I grep for 2 pattterns and have them listed side by side?

Ubuntu 16.04 bash -version GNU bash, version 4.4.0(1)-release (x86_64-unknown-linux-gnu) I would like to grep for 2 patterns and then have them listed side by side. ATM, this is what I have: root@...
3
votes
1answer
7k views

How to escape new line characters for json?

I have a file that contains new line characters. I am posting the file via curl to a server that would parse it as json. It rejects the request due to the new line characters. But when I do: $(echo ...
1
vote
2answers
478 views

Merging four new line delimited json files using jq

I am trying to merge 4 JSON files (in the future maybe two more). The only common factor between the newline delimited JSON files is "vulnid". File 1: {"vulnid":"cve1", "product":"product1"} {"...
0
votes
1answer
3k views

Export JSON to CSV with Headers using JQ

I have a (dictionary?) JSON file, similar to: { "Salad": { "name": "Dressing", "good": true, "status": true }, "Data_XML": { "name": "XML", "good": false }, "...
1
vote
1answer
299 views

Variable in curl adds backslashes to string

I am trying to use curl based on some variables to create customers in Stripe, but when I assign the token to a variable it is giving me an error on Stripe saying that it does not exist. However, if I ...
1
vote
1answer
73 views

replace tab with space

input json: [ { "name": "cust1", "grp": [ { "id": "46", "name": "BA2" }, { "id": "36", "name": "GA1" }, { "id": "47", ...
0
votes
1answer
398 views

jq - convert milliseconds

input json: { "id": "3885", "login": "050111", "lastLoginTime": 1529730115000, "lastLoginFrom": "192.168.66.230" } { "id": "3898", "login": "050112", "lastLoginTime": null, "...
3
votes
2answers
5k views

jq - print values in one line

json input: [ { "name": "cust1", "grp": [ { "id": "46", "name": "BA2" }, { "id": "36", "name": "GA1" }, { "id": "47", ...
6
votes
1answer
3k views

jq - print “-” for null values

input json: { "id": "3885", "login": "050111", "lastLoginTime": 1529730115000, "lastLoginFrom": "192.168.66.230" } { "id": "3898", "login": "050112", "lastLoginTime": null, "...
2
votes
1answer
3k views

Extract value from JSON document returned by curl

[ec2-user@ip-10-0-1-238 ~]$ curl "https://tools.keycdn.com/geo.json?host={18.205.6.240}" {"status":"success","description":"Data successfully received.","data":{"geo":{"host":"18.205.6.240","ip":"18....
2
votes
1answer
235 views

Delete Substring from JSON file (malformed)

I am trying to delete different values from a JSON file. It's not pretty and jq returns 1 compile error. I am searching for a solution from the command-line (awk/sed). Here is my sample data from my ...
0
votes
3answers
66 views

remove line if word start in line

we are trying to the delete the line that started with "content" word but without success "content" word actually can start in the begging of file or after spaces or TAB what is wrong in the sed ...
0
votes
1answer
383 views

Interpolate within single quotes

I have the following: COMMENT="A random comment" TEXT_JSON='{"person" : "Jim","comment" : "$COMMENT"}' echo "$TEXT_JSON" | jq . This prints { "person": "Jim", "comment": "$...
1
vote
1answer
98 views

extract piece out of JSON line

I've got a number of JSON lines that are pretty long (~1.5KB) and may look something like: "XYZ":{"myString":"myValue",ABCD} and I only want to extract "myString":"myValue" from the whole line. grep ...
10
votes
5answers
2k views

awk/sed/perl one liner + how to print only the properties lines from json file

how to print only the properties lines from json file example of json file { "href" : "http://master02:8080/api/v1/clusters/HDP/configurations?type=kafka-env&tag=version1527250007610", "...
0
votes
6answers
1k views

awk/sed/perl one liner to edit json file

We want to add the folwing lines: export KAFKA_HEAP_OPTS="-Xmx8g -Xms8g" and: export KAFKA_JVM_PERFORMANCE_OPTS=" -XX:MetaspaceSize=96m -XX:+UseG1GC-XX:MaxGCPauseMillis=20 - XX:...
2
votes
1answer
54 views

find lines longer than X in JSON and delete the whole object

I have a huge JSON Array with multiple thousand objects and I need to filter all objects where the text field is too long (say 200 chars). I've found a lot of SED/AWK advices to find a line with a ...
2
votes
0answers
232 views

process JSON format with JQ tools [closed]

I want check format keys in bash script. In my json if any keys match this format key[0-9][0-9]_$ my script exit 1 else exit 2. I want use JQ tools. Bash: #!/bin/bash json=$(cat <<EOF {"key11"...
0
votes
1answer
2k views

Check whether any value is zero using jq and return 0 to the calling shell script

I have this JSON file: { "key11":1010, "key12":12120, "key13":12103 } How can I use jq to check whether any of the values corresponding to a key[0-9][0-9] are zero, making jq exit ...
5
votes
3answers
5k views

How can I pretty format a JSON file, with all the correct indents and everything?

I have a JSON file on CentOS where all text is on the same line. How can I pretty format it with all the correct indents and everything?
4
votes
1answer
3k views

Match keys with regex in jq [closed]

I'm writing a script that analyses JSON input (jsonfile): { "key11":1010,"key11_yes":13,"key11_no":14, "key12":12120,"key12_yes":9,"key12_no":25, "key13":12103,"key13_yes":13,"key13_no":20 ...
3
votes
1answer
3k views

jq - select hostname starting from a string

input json: [ { "id": "89", "hostname": "abcd" }, { "id": "89", "hostname": "babcd" } ] How to modify below filter to get on output only hostname beginning with "abcd"? $ jq ...