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
1
vote
1answer
28 views

Handling null (empty array) while converting json to csv with jq?

When trying to convert json to csv, I get an error about null with the following jq query: printf "[]" | jq -r '(map(keys) | add | unique) as $cols | map(. as $row | $cols | map($row[.])) as $rows | $...
2
votes
1answer
21 views

What is the difference between vertical pipe and juxtaposition in JQ?

My program returns JSON into stdout and it is an object with operations field, which contains a list of operations. Each operation contains fields including id fields, for example: { "operations":...
1
vote
2answers
30 views

Pass variable within json payload in shell script

In the following scenario, which is the way to pass ${MY_ENV_VAR} in the payload? I will have to escape: a) the single quotes of the payload b) the double quotes of the value of the text json ...
0
votes
1answer
37 views

Cronjob fetching JSON with cURL. Check if response isn't empty before writing to file

I'm running Ubuntu and got a simple cronjob fetching a remote JSON-file and (over)writing it to the server. */15 * * * * /usr/bin/curl -m 120 -s https://path/to/remote/json.json > /store/json/here....
0
votes
1answer
27 views

trim using sed to get the exact value from curl

I'm getting this string data from curl command {"password": [["passwordreal", "2035/01/01 00:00"]], "user": "user1", "address": "kobebkokoko.net"} How do I get passwordreal using sed? Example, ...
0
votes
1answer
33 views

CSV to NESTED JSON

I need to convert a CSV file to a JSON output, I'm using the csvtojason library from https://www.npmjs.com/package/csvtojson, csv File: mode,device,stb,data,data1,data2,data3,data4 modelo1,device1,...
0
votes
0answers
36 views

Add bash variable as JSON key and value into object

I have a JSON array of objects like so . [ { "id" : "tmp1387816934708382026", "owner" : "john", "x11-display" : ":5", "x11-authority" : "/run/user/john/dcv/tmp1387816934708382026....
0
votes
2answers
66 views

How to write routine to escape double quotes in a JSON string [closed]

I have to be efficient so I can't use tools like jq which loads up a big binary executable. I just want to escape double quotes in a string so it's safe for JSON. This isn't good enough: echo ' bad \"...
0
votes
1answer
61 views

If/else within a grep statement

I am trying to find all instances of "type":"FollowEvent", and then within those instances, if the string "actor": is not followed by {, then capture the string enclosed in " that comes immediately ...
0
votes
1answer
69 views

Get parent nodes by child node selector with jq

I'm trying to parse json with jq { "xxx": { "aliases": { "business_event": { "is_write_index": true } }, "mappings": { "...
0
votes
1answer
44 views

Rename files based on JSON content using jq

I need to make a shell script that uses jq to rename below mp4 file(s). (could have use jasonpipe but didn't know how to install it on mac) File Dowloaded: title1-1000221327.mp4 title1-1000221327....
1
vote
1answer
218 views

Convert json file to a “key-path” with the resulting value at the end of each “key-path”

I have a large and relatively complex json configuration file that I want to search for keys and/or values using simple tools like "grep". When I 'grep' the file I would like to have in the output ...
0
votes
0answers
84 views

iproute2 - ip addr json import

I can get a json export from my network configuration with following command: ip --json addr show result: [ { "ifindex": 1, "ifname": "lo", "flags": [ "LOOPBACK", "UP", ...
0
votes
4answers
117 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,...
1
vote
1answer
268 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
422 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
vote
1answer
64 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
544 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
83 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
45 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
811 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
2k 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
249 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
142 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
69 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
103 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
379 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
170 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
62 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
219 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
115 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
83 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
3k 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
743 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
77 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
51 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
734 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
100 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
366 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
186 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
550 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
252 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
880 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
118 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
872 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
49 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
69 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
2k 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
51 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 ...