Stack Exchange Network

Stack Exchange network consists of 175 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
4answers
100 views

sed command to replace a value in a config file

I'm working on an automation script and I need to change the value in a config file. The config file that I'm trying to edit has a line like this (including the spaces before): "peer-port": 23456,...
0
votes
0answers
16 views

Passing variable to jq to edit a json file

I am trying to pass a variable into jq like this '.Linux.date.$var' so far I have tried quoting them by name which is working fine. But I want to use variable to call them. I have this, which is ...
1
vote
1answer
44 views

jq (command-line JSON processor) merge multiple JSON strings from STDIN

I am trying to merge two different JSON strings from STDIN (using pipe, not files) using jq command. Here's the command trying: curl ipinfo.io api.ipify.org/?format=json 2>/dev/null | jq -s ...
-1
votes
0answers
28 views

How to work with JSON in python [migrated]

My Python Script gives a JSON output. How can I see it in the proper JSON format? I tried with parsing with json.dumps() and json.loads(), but could not achieve the desired result. ======= Myscript....
1
vote
1answer
37 views

Convert JSON with raw characters in string

Had a problem with a tool that was generating illegal JSON. Some of the JSON strings contained characters in the range 00-1f. So I wanted to convert these characters to correctly escaped valued \...
1
vote
2answers
91 views

Loop into JSON Array in Bash Script

I make a curl request to an API and get a json return with jq. The result { "errors": [], "metadata": { "clientTransactionId": "", "serverTransactionId": "20190318164551347" }, "...
2
votes
0answers
31 views

JSON -> csv creating header line and padding header if found empty field

I have a programme in bash that get JSONline files with several million of these object per line (See source) { "company_number": "09626947", "data": { "address": { "address_line_1": "...
1
vote
2answers
41 views

How could I (painlessly) split or reverse “Last, First” within a record in Miller?

I have a tab-delimited file where one of the columns is in the format "LastName, FirstName". What I want to do is split that record out into two separate columns, last, and first, use cut or some ...
-3
votes
3answers
168 views

script to translate xml to json

I have 5000 questions in txt file like this: <quiz> <que>The question her</que> <ca>text</ca> <ia>text</ia> <ia>text<...
9
votes
4answers
1k views

Wrap all numerics in JSON with quotes

There are JSON data which contains some numeric values. How to convert all numerics to strings? (wrap with quotes) Example: { "id":1, "customer":"user", "plate":"BMT-216-A", ...
-1
votes
2answers
106 views

Using filter condition in python -mjson.tool command

Can I use a filter condition in python -mjson.tool command to select objects which has specific attributes? For example, I have a sample.json file with for objects out of which two has an attribute "...
1
vote
2answers
87 views

How convert bash output to JSON with key {#PROCNAME}?

I try get JSON with top 5 process by memory. This JSON i want send to Zabbix and draw top 5 process by memory. I get top 5 process by memory by command: ps axho comm --sort -rss | head -5 node ...
1
vote
2answers
57 views

Update file with multiple values automatically

I have a hosted zone and record set that route to multiple addresses. I'd like to update the record set with adding or removing one IP address in the list. Unfortunately, AWS CLI doesn't provide the ...
-2
votes
4answers
95 views

Json. How to add a sentence after :

The following is an extroct from a json file, that I have: }, { "name": "asdasd", "script": "dsad.js", "merge_logs": ture, "error_file": "/ofghfghgfh.log", "out_file": "/...
1
vote
1answer
130 views

Combining youtube-dl and VLC without a pipe

youtube-dl -o - <webpage> | vlc - shows a video in VLC. However, the video is piped (through something like fd://0), which inhibits the possibility to jump forwards/backwards. However, youtube-...
0
votes
3answers
106 views

jq is not appending json file

I have a json file like this: { "active": "secure", "secure": { "nodetype": "secure", "nodeid": null, "servers": [ "ts2.na", "ts1.na", "ts3.na" ], "stakeaddr": null, "email": ...
1
vote
1answer
53 views

Script to modify the structure of a JSON file

I'm looking for a script that can solve a problem I'm having with a JSON file. The thing is that an API is delivering this file to me: { "device 1":{ "general_data":{ "descriptions":...
0
votes
1answer
111 views

make json from SQL query output

I have this query: select hostname,size from tableinfo output is like this: hostname size ------------------------- ----------- host1 28 host2 ...
0
votes
1answer
65 views

How to get value with JQ (JSON) [closed]

I want to get the value of result.data (but it gives me null) can somebody explain me how targeting in the json below works. Do not understand it. { "ActTime" : 1547809207, "AstrTwilightEnd" : "...
0
votes
1answer
43 views

Need to associate one field with another in event, using bash script

I've gotten most of what I need done, but am stuck at the last part. I need to download the campaign from this month, but the url is associated w/ a campaign id and not the month (makes sense). I need ...
0
votes
3answers
71 views

Linux sed command replace two lines having spaces and special characters using regular expression

I have one file having following example text. "list-value": { "object-value": { "value": "example-value-123" } } I want to change value text "example-value-123" by matching pattern ...
1
vote
3answers
528 views

How to extract a value from json response using shell script

{"expand":"renderedFields,names,schema,operations,editmeta,changelog,versionedRepresentations","id":"15114","self":"https://brg-jira-tst.state.mi.us/rest/api/2/issue/15114","key":"BRGTEST-11","fields":...
3
votes
2answers
320 views

parse JSON and malipulate its object values

I have a json file named xyz.json as follows [ { "annotations": [ "a" , "b" , "c" ], "class": "image", "filename": "vc00_02201.png" }, { "annotations": [], ...
1
vote
1answer
74 views

Data Cleaning Using Shellscript

I want a combined query suitable for selecting rows where lang = en i.e. language is equal to English and removing the other rows while I convert this file from JSON to CSV. json2csv -i Downloads/30....
2
votes
1answer
49 views

Look for multiple line string from bash

I am currently working with Jupyter notebooks. With an IDE I used to be able to look for parts of my code that could be elsewhere, and thus refactor as needed. Suppose I have the following code: ...
3
votes
3answers
473 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
72 views

Slicing JSON with JQ to Create Arrays for New Relic Ingestion

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 script and WPCLI and then ...
-1
votes
2answers
216 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
101 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
283 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
2answers
115 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": "...
3
votes
1answer
519 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
85 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
540 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
3answers
46 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
61 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: { "...
1
vote
2answers
909 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
42 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
5answers
3k 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
1k 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
2k 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
174 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
113 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
96 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
92 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
109 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
349 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
136 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
268 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
427 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": [ { ...