Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

0
votes
0answers
16 views

Add a Key Value Pair in JSON Object Using JQ and Bash

I have a script that crawls through a directory and pulls info from WP sites and builds a JSON array of objects that will eventually be fed into a visual dashboard. The script works perfectly but I ...
3
votes
2answers
68 views

how to parse specific values from multiple JSON objects into csv using jq

I have following json [ { "ip":"105.105.105.105", "timestamp":"1543746097", "ports":[ { "port":80, "proto":"tcp", "status":"open", ...
0
votes
1answer
21 views

Slicing JSON with JQ to Create Arrays for New Relic Ingestion

sorry for the long title. I need to take some JSON, slice it using JQ so New Relic can parse it properly as it only takes a specific format when pushing JSON to their dashboards. I am using a bash ...
-1
votes
2answers
40 views

jq: colorize selected field of json file [closed]

Extend of this question: jq: parse json file with constraint from other field After select "name" field I'd like to colorize it: { "checksum": "9e44bb7b76d8c39c45420dd2158a4521", "roots": { ...
0
votes
1answer
20 views

jq: parse json file with constraint from other field [duplicate]

Extend of this question: How to combine strings from JSON values, keeping only part of the string? Above link's output also include the "name" of folder type, need to exclude these "type": ...
2
votes
2answers
62 views

Remove trailing commas from invalid json (to make it valid)

Let's say I have a file as below { "fruit": "Apple", } I want to remove the comma at the end of the line, if and only if the next line contains "}". So, the output will be : { "fruit": "...
1
vote
1answer
21 views

JQ (GET ID based on NAME)

I get a long list of such arrays { "id": "byu6g6c4cjys5mdkg5znh8ju8c", "create_at": 1511875272294, "update_at": 1511875272294, "delete_at": 0, "display_name": "BMA", "name": "...
2
votes
1answer
229 views

How to combine strings from JSON values, keeping only part of the string?

I have sample: "name": "The title of website", "sync_transaction_version": "1", "type": "url", "url": "https://url_of_website" I want to get the following ...
1
vote
2answers
25 views

How to extract array from within json to a separate txt file

I have a .json file that I need to extract the SliceTiming field from into a separate txt file. I cannot use jq. If I could, my command would be jq .SliceTiming[] *.json Here is the .json file { "...
0
votes
2answers
87 views

How to convert shell output to JSON?

I have this output in the following and I am trying to convert it to JSON api format. I want to know how can I do it. rock64@rockpro64:~$ sh MACscript.sh eth0 11:1d:11:11:11:1d lo 00:00:00:...
0
votes
2answers
40 views

Filter out random username after string

I have a full list of API status with lots of information like that. I need to grep the name of the username so I can send it to another file or variable. For example: [{"id":"...
0
votes
1answer
45 views

Json transformation using jq

I want to transform json to new line delimited json. I was attempting to do it multiple times using jq in bash, but I have not been able to get even close to the final output. INPUT: { "...
0
votes
1answer
40 views

Get values for a given key and its parent with jq

I've got a JSON array like so: { "1": { "available_memory": 1086419656.0, "available_memory_no_overbooking": 1086419656.0, "conns": 1.0 }, "2": { "available_memory": 108641236.0,...
-2
votes
3answers
36 views

Find and replace inside string based on pattern and exception cases

I have a JSON string that returns some key value pairs but if the value is numeric it doesn't enclose it with double quotes so my JSON parsing isn't working for those cases. My idea is to manipulate ...
4
votes
4answers
644 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
0answers
45 views

Where's the documentation for the JSON format of LVM

I've noted that there is an option to use JSON format for commands like vgs which sounds nice if you're scripting. However I've not found any documentation on the format. Especially what I find not ...
0
votes
1answer
118 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 "...
4
votes
2answers
478 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
92 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
76 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
51 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
73 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
29 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
2answers
80 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
75 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
60 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
119 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
85 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
42 views

Minimized JSON code between two patterns with regex

Let's take a file with for example : "test": [ { } ], "test": [ ...
3
votes
1answer
81 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
161 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", ...
2
votes
2answers
2k 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
56 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
37 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
109 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
83 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
1k 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 ...
0
votes
1answer
318 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, ...
3
votes
5answers
4k 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
756 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
325 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
82 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
112 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
375 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@...
2
votes
1answer
3k 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
232 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
1k 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
206 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
29 views

replace tab with space

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

jq - convert milliseconds

input json: { "id": "3885", "login": "050111", "lastLoginTime": 1529730115000, "lastLoginFrom": "192.168.66.230" } { "id": "3898", "login": "050112", "lastLoginTime": null, "...