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
3answers
26 views

How to use argument in single quotes

I have a file, which contains ids: 123abc 456dbc I want to pass them in to a command while I iterate over the the file. Currently, my command works like this: part_of_command '{"id":{"...
0
votes
2answers
23 views

Fetch partial data from JSON Format data by jq

I have a sample JSON format data [ { "info":{ "disk_num":"2", "hostname":"hostA", "net":[ "eth0&...
3
votes
1answer
39 views

jq - set a value to another value conditionally

I need to set the value of a field in a json doc to one of three values using jq, depending on which exists. Notionally this looks like: set X to (if A exists, else if B exists, else if C exists, else ...
2
votes
2answers
104 views

How to extract out elapsedTime attribute values from file

I wish to extracted out elapsedTime attribute values from the file. Records look {"realm":"/test","transactionId":"9e26c614","elapsedTime":17,"...
2
votes
3answers
114 views

Table records to convert into JSON file in unix with jq

I have table on a Linux machine which has a number of records; I am running a query to get: select * from TABNAME_XYZ CID CN XY NAT UIC DATE Region 12 2123 120.9 29.0 100.0 ...
0
votes
1answer
28 views

Delete text from files using regex with sed

I'm attempting to use sed to remove some lines from json files. As you can probably tell, I'm very much an amateur but think I have the regex correct. However sed throws various errors including ...
-1
votes
2answers
63 views

how to parse non-standard Json?

I am using curl to retrieve data. the output is Json output but it's not standard. I tried using jq but i get null output. for example: I want to extract all IDs from this output and store them in ...
0
votes
1answer
41 views

How can I get jq to produce the array of values of a json dictionary?

I have a json dictionary $ cat foo.json { "black": "#073642", "red": "#DC322F", "green": "#859900", "yellow": "#...
1
vote
2answers
50 views

Source a file template and output it with set variables

I have a sort of json template file like this: # INPUT file.json { "set1":{ "string1": "${VAR1}", "string2": "${VAR2}", ...
1
vote
1answer
77 views

How may I convert this JSON into CSV?

I have below JSON document to convert into CSV. I need to iterate over the first column with the 2nd and 3rd (they can be either string or array) at the same time as one iteration. Example document: [ ...
0
votes
1answer
32 views

Parsing JSON with JQ using numerical key

I have a below curl which passes the value 2000 in the jq command which returns the right value... curl -X GET \ -H 'vmware-api-session-id: <auth-id>' \ -k -s 'https://<url>/api/...
7
votes
2answers
511 views

how to jq nested array without key (only value) and convert to csv

I hope someone can guide me how do I convert below json to csv that I'm expecting for. Much appreciated in advance. Update: thanks for the solutions provided, but I found that sometimes array does not ...
2
votes
2answers
52 views

How to replace a value in json file using jq and returning the whole content

I have a json like this { "AgentGroupId": null, "AgentId": null, "CreateType": "Website", "IsPrimary": true, "IsShared": true, &...
0
votes
4answers
146 views

how i parse following json array format. i want this filename value in bash or groovy?

How do I parse the following json array format? I want the filename value filewhichisdeploy in bash or groovy { "filewhichisdeploy":[ { "filename": "value" ...
2
votes
1answer
36 views

Convert types from strings to ints in newline delimited JSON file, handling null

We have the following newline-delimited JSON: {"leagueId": "1", "name": "the ballers"} {"team": "2", "leagueId": "1", &...
-2
votes
2answers
73 views

change order of lines position in json file [closed]

i want the row of description to be after row of body EXAMPLE. from: { "foo": { "prefix": "foo", "description": "foo", &...
3
votes
1answer
77 views

Dynamically escape a variable

I'm writing a name-helping script to automatically set the "name": field in a package.json file so that it matches a certain regex structure, but I'm having some issues actually setting the ...
5
votes
1answer
109 views

Search, separate, and purge txt values

What's really tripping me about this is the quote marks. I have a file.txt with lines like: {"a":"town, state, country","e":["john@company.com"],"n":&...
0
votes
3answers
35 views

In-place change of text (using whatever tool) in JSON file

I am on a VPN with port forwarding, and already have my script to get an obtained forwarded port, open that port in iptables, but what I don't have is an automation of changing this port in ...
0
votes
4answers
164 views

Replace a filename in a JSON document by the contents of that file

My aim: replace filenames by their contents in a JSON file with a command sed or awk or other... An example: JSON file to modify (file.json) ... "value": "{{<test/myData.txt&...
0
votes
1answer
78 views

How to update given environment variable values in json

I need to use the below json file as input and this file could contain multiple variable entries. I need to search var1 or var2 in environment variables and replace the value in below json. { "...
2
votes
3answers
140 views

How to create CSV with headers from JSON using jq

I am trying to create a csv file with headers from a json using jq. I have the following snippet https://jqplay.org/s/H_U5mxbTFW Question: How can I print the values of peerings > accept_vpc_info &...
1
vote
1answer
387 views

convert JSON array to space separated string

I have a JSON file like this: { "name" : "Allow", "source" : [ "*" ,"0.0.0.0"] } I need to parse this JSON so the array of strings inside JSON can ...
3
votes
1answer
448 views

How to get stamp in shell script in JSON file using jq tool?

I have question regarding shell scripting and jq tool to create a json file with timestamps. echo "{\"vtg\":[$value]}" | jq -a '. + {date: now|strflocaltime("%r")}' > ...
1
vote
5answers
356 views

How to parse a particular ids from a text file?

I have a lengthy text file, partial file content is shown below, [{"site":"1a2v_1","pfam":"Cu_amine_oxid","uniprot":"P12807"},{"site&...
2
votes
1answer
49 views

Applying simple string mappings on JSON files

Somehow I think there must be a one-liner to apply a simple mapping on the command line. In this case the keys in JSON will (as usual) provide context, ensuring that we don't foolishly replace strings ...
3
votes
2answers
500 views

Flattening JSON lines arrays with JQ

I can write > echo '{"a": "arbiter", "b": "brisk"}{"a": "astound", "b": "bistro"}' | jq '.a, .b' "arbiter" &...
2
votes
2answers
44 views

Can I directly convert a file that lists multiple variables to JSON using the command line?

Let's say I have a file with the following content: var1='a random text' var2='another random text' var3='a third random text' I know that if I use the command eval like the following I'll store all ...
3
votes
1answer
135 views

jq find value corresponding value from other key

I have a output of curl | jq: { "ssh_keys": [ { "id": 30482248, "fingerprint": "21:57:08:d8:41:0f:89:57:0b:96:95:64:ff:59:50:69", "...
2
votes
1answer
289 views

Extract a specific key's value from a JSON file

I've got a huge JSON that looks like this. Sample { "Key": "4fa21496-3534-4480-8405-a0f7699a915e", "FirstName": "XX", "XX": "Liggins", ...
-3
votes
2answers
172 views

get specific string from json data using jq [closed]

I only want with from the sample file below. This is just for refernece, cannot paste company code here as it runs on secured environment so not allowed but my problem is somewhat similar. I have to ...
4
votes
2answers
3k views

How to edit a JSON file using shell?

I am building a shell script that uses a JSON file. { "property1": true, "list": [ { "id": 1, "name": "APP1" }, { &...
3
votes
1answer
366 views

jq print parent name, values, and children values

I'm new to jq, but I'm confident it can help my workflow once I figure it out. I have been provided with some data that looks something like the below: { "parent_name1": { "...
1
vote
2answers
121 views

Pass the variable value to curl JSON

I am trying to create a JIRA ticket using curl POST method, but the variable substitution is not happening properly in TODAY_DATE variable. If i remove that it is working fine. ANy hint on how this ...
2
votes
1answer
59 views

Rename a JSON key after a specific pattern

I have a JSON object with the following content: { "quiz": { "sport": { "id": "77", "q1": { "...
1
vote
1answer
45 views

Get content of files with same name in subfolders to obtain a JSON array

I have the files in folders that begin with 28-. They are one wire bus sensors to measure the temperature. The Raspberry recognize them via its SPI interface; every probe has its ID (something ...
2
votes
1answer
731 views

Jq Invalid numeric literal at EOF

I'm try to add in a Json file a record structured for Raid info jq '.raid.c0.e252.s0 +={"device": "/c0/e252/s0"}' file.json But I got 2 errors: jq: error: Invalid numeric literal ...
-3
votes
1answer
543 views

Json to Table format using shell script

sfdx diff | tee result.json ; Here i am getting result/response in json which i am adding to result.json file. Below is the json i am getting { "status": 3, "result": { &...
0
votes
1answer
216 views

How to send JSON message to SLACK?

I have a following JSON file: { "blocks": [ { "type": "section", "text": { "type": "mrkdwn", "text&...
2
votes
2answers
1k views

Using jq, how to replace the value of particular key?

How to replace the xxx with yyy? { "spec": { "template": { "spec": { "containers": [{ "args&...
0
votes
2answers
461 views

How to extract the first field/value on a json file using jq

I have a JSON file that has this content: { "Message": { "greeting": "hello" } } { "Message": { "greeting": "Bonjour" } } { ...
2
votes
2answers
373 views

how to extract fields of info from github api using jq

I am trying to extract some info about github repositories using its API, apparently jq is the way to go. I can use this command to view all the available info: curl 'https://api.github.com/repos/tmux-...
2
votes
1answer
76 views

What means the definition of path and leaf array in jq --stream man page

In the jq manual page, --stream option, says: Parse the input in streaming fashion, outputing arrays of path and leaf values (scalars and empty arrays or empty objects). For example, "a" ...
1
vote
1answer
336 views

How to use json variable in shell script file?

I would like to use this json file to get jenkins version and java version numbers to include my script.sh file. How do we do that? I tried {{user `java_version`}} but it did not work. variable.json ...
-3
votes
5answers
140 views

How to read list in JSON file using awk and sed

I have a list in JSON file apps.json: { "properites":{ "apps":["apple","orange","mango"] } } I need to read this file and get of objects. I used: ...
1
vote
2answers
66 views

awk Group By & "Reduce"

Let's say I have data like the following: table_name id table_name col_1 table_name col_2 another_table_name id another_table_name col_1 How can I use awk to group by the first column and reduce the ...
0
votes
1answer
133 views

MacOS/Windows - How to extract specific .json file from multiple zips and renaming the .json file as folder it was extracted from

I am dealing with cuckoo sandbox exported data having report.json file under each Zip file eg > 123456.zip each zip has the file in zipfile/reports/report.json i have multiple zip files in a folder ...
0
votes
1answer
68 views

AWK: field operations on "altered" FS and "chaining" operations together

I'm writing a script that uses awk to parse JSON data from MediaWiki API pages in order to retrieve information from Wikipedia tables. This is the sample I'm working with, that's being piped into awk. ...
2
votes
1answer
2k views

Add key/value to json object

I have a json object stored in a shell variable json: { "name": "foo", "array": [ { "name": "bar", "thing&...
0
votes
2answers
65 views

Bash replace multiple lines in a file between two patterns with the content of another file?

I have a long javascript file long.js which has this content as a part of it ... more lines ProcessCoverageController.createExampleQueries = function () { return [ { title: '--...

1
2 3 4 5
8