2022 Developer Survey is open! Take survey.

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
0 votes
1 answer
12 views

Json data fetch thourgh jq

how do we fetch the email of level:2, from below json and expected output will be jeenav.b@xy.com. any suggestion please { "escalation_policy": { "on_call": [ { ...
user avatar
  • 41
2 votes
1 answer
69 views

bash how to concat multiple json files to one

I have thousands of json files that look like: file1 (key1:value_list1) {"2mac:acg":["1-248","3-245","3-246","4-245","4-246","5-245&...
user avatar
  • 155
0 votes
1 answer
38 views

Jq substract 2 keys and add it to json

I have a json like this one { "status": "InProgress", "transactionId": "1652807586", "startTime": "2022-05-17T17:13:06Z", "...
user avatar
0 votes
3 answers
155 views

Find number of lines between a pattern inside specific filetype

I have a notes.json file inside each directory. The following command counts length of each notes.json file and returns a sorted output by each file's number of lines. find . -name notes.json | xargs ...
user avatar
  • 7
2 votes
1 answer
46 views

How to parse an escaped json string with ansible/jmespath/jq?

I'm using the Ansible module for Bluecat to make an authorized API call to get some information about a subnet. The response looks something like this: "result": { "changed"...
user avatar
1 vote
2 answers
68 views

How to merge arrays from multiple arrays in two JSON with JQ

I have two JSON files (file1.json and file2.json) with the following same structure as defined below with two array lists as shown below. The first file is (file1.json): { "Lists1": [ { ...
user avatar
  • 13
-1 votes
1 answer
35 views

Print json output to single line with comma separated

I am new to JQ, I have below json file [ { "userId" : "jens", "firstName" : "jens", "lastName" : "jens", "...
user avatar
  • 29
-1 votes
1 answer
35 views

Convert JSON to table, with headers of "Key" and "Value"

I have the following JSON output: [ { "enabled": "true", "policy_profile": "custom", "scan_local_files": "true", "...
user avatar
0 votes
2 answers
68 views

Nushell: Convert list to table

Is there an idiomatic way to convert a list of similar records into a table in Nushell? I'm working with the Stack Exchange API and getting results back something like: let questions = ('[ { &...
user avatar
  • 2,300
1 vote
1 answer
87 views

How to remove a specific JSON object from a file?

I have the following JSON data in a file: { "packages": { "cc": { "name": "cc", "version": "3.1", "release"...
user avatar
0 votes
1 answer
30 views

How I get values from a JSON document in bash?

I want to write a script that finds my unused volumes in AWS. (the 'status' of used volumes is 'in-use'). When I use the aws ec2 describe-volumes --filters Name=status,Values=available I got the next ...
user avatar
-1 votes
1 answer
64 views

How can I remove the start and the end with sed?

How could I remove first ./ and the end / from my path? right now my code has: sed -i 's/dir2\/file-example.json//' test.sh and it prints out like this: ./dir1/ but I would like to have it like this: ...
user avatar
9 votes
1 answer
178 views

extracting the CmdName_Word - Word from a morbig-generated JSON file

I would like to extract the commands from arbitrary shell scripts. I've used morbig (hat tip to Michael Homer for the suggestion!) to generate a JSON file from a shell script. As an example, this ...
user avatar
  • 63.1k
-1 votes
1 answer
57 views

Use conditional formatting in jq - PowerShell [closed]

This is a follow up question from this question that got contributed by another person. I have following output from a webserver: { "status":"OK", "result":{ ...
user avatar
  • 1
0 votes
1 answer
41 views

Use conditional formatting in jq

This is a follow up to this question asked by me a few days ago. Say I have this output from a webserver {"status":"OK","result":{"string1":{"variable"...
user avatar
  • 3
0 votes
1 answer
38 views

How do I extract the content of quoted strings of a specific property path from an output?

I have an output from a web server response in JSON which looks like this: {"status":"OK","result":{"string":{"variable":0},"string2":[{&...
user avatar
  • 3
0 votes
2 answers
74 views

I want to extract version from text file from certain line and use it as a command

For example my text in the file "somefile.json": { "dependencies": { "name1": "text1#version1", "name2": "text2#version2", &...
user avatar
  • 1
-3 votes
1 answer
157 views

fillter json data with jq and print count of occurrences

im trying to fillter below json data with jq and expect ouput as below { "data": [ { "topic_name": "BookShow", "topic_id": "ABCDFG", ...
user avatar
  • 41
-6 votes
1 answer
52 views

How to extract only JSON from a webpage? [closed]

As rendered, a webpage has solely or primarily JSON. I want to save only all the JSON in it into a file. Just take all JSON (even if it is organized in different "chapters"). How to do that? ...
user avatar
  • 115
0 votes
3 answers
138 views

Regex to match JSON in an HTML

From this JSON-HTML webpage I want to filter out only lines with this pattern: "realname": "SOME_VALUE_COMES_HERE", I tried this: curl https://www.mediawiki.org/w/api.php?action=...
user avatar
  • 115
-1 votes
1 answer
336 views

filter array of objects using jq from json

im trying to fillter the below json data with jq and expected out-put as last. cat data.json { "params": { "filters": {}, "group_by": [ &...
user avatar
  • 41
0 votes
0 answers
29 views

How to convert a multiple choice text file into a json file with indents

How can I convert a text file into a JSON output like below? Text file: Question:'Which of the following commands can be used to perform a full text search on all available packages on a Debian system?...
user avatar
0 votes
1 answer
555 views

How to make jq output into a variable

here is my code curl random args "link" | jq and gives it gives is { "id": "961438154596153411", "username": "testing", "avatar": &...
user avatar
0 votes
1 answer
46 views

Delete only certificates in big acme.json

I am trying to figure out how to format big json file and delete only certificates from while which is formated like this: { "http-01": { "Account": { "Email":...
user avatar
  • 338
1 vote
1 answer
153 views

reformat json using jq

I have the below JSON file: { data : [ { "name" : "name1" "date" : [ { "date1" : "aaa", "date2" : "bbb" ...
user avatar
  • 13
1 vote
2 answers
449 views

Is there a way for 'jq' to read json with single quotes instead of double?

I use jq as an efficient way to parse out large nested json files. I sometimes want to us jq with a json formatted file which has single quotes instead of double around keys and values like below: { ...
user avatar
0 votes
1 answer
161 views

How to grep from file names with number in range

Assume I have a directory with 5,000 files. each with a name such as: 1.json 2.json 3.json .. 4000.json 4001.json what command-line utility can I use to grep for a string from only the files 1.json ...
user avatar
-2 votes
1 answer
56 views

how to txt -> json convert?

C-11^Mark^Docking AWS C-12^Mark^Docking AWS C-13^Lay^Ploting C-14^Lay^Ploting C-15^Lay^Ploting C-16^Vincent^GPU Calc C-17^Vincent^GPU Calc C-18^Vincent^GPU Calc C-19^Vincent^GPU Calc I use this ...
user avatar
2 votes
1 answer
88 views

Changing text into JSON

Example of input data (^-delimited fields): C-11^Mark^Docking AWS C-12^Mark^Docking AWS C-13^Lay^Ploting C-14^Lay^Ploting C-15^Lay^Ploting C-16^Vincent^GPU Calc C-17^Vincent^GPU Calc C-18^Vincent^GPU ...
user avatar
0 votes
1 answer
57 views

Write sed command to input file

I'm building a script to automate boilerplate. In it, I append a string: "compile": "browserify js/main.js > ./dist/bundle.js -t babelify", "watch": "watchify js/*...
user avatar
  • 143
2 votes
2 answers
217 views

append a json block before specific line using jq

I have a scenario where I already have a json file which I want to open and edit using jq. json file(temp.json) : { "a":{ "keya" : "abc", "keyb" : &...
user avatar
  • 85
1 vote
2 answers
315 views

Add new line after a string match in JSON file

I need a help doing the below task. In a JSON file I have a part something like below "Principal": { "AWS": [ "arn:aws:iam::12345677890:...
user avatar
0 votes
1 answer
168 views

sway get the layout of the currently focused container

How do I get the layout of the currently focused container in sway (eg. 'splith', 'tabbed')? I guess the best way would be to parse the JSON output (sample below) of swaymsg -t get_tree using jq, but ...
user avatar
1 vote
2 answers
173 views

Require curly braces in bash variable expansion

Is there a bash option or another way to make bash to only expand curly-braced variables like ${var} and ignore regular ones like $var? Update - here is why i want that: I have a relatively large ...
user avatar
2 votes
3 answers
375 views

Extract values between two patterns

I am using Ubuntu and I want to extract the values between two patterns and the required string is not in the file. My data is as shown below: [{"rows":[{"_uuid":["uuid",&...
user avatar
0 votes
1 answer
538 views

Use jq to update property of object that contains other property with specific value

Using jq, is it possible to update values of an object with a specific value is some other property? In the example below I'd like to set the value of the "value" property of all objects ...
user avatar
1 vote
1 answer
260 views

Correct escaping of wildcard when using jq

The command below works: $ echo '{ "a": [ { "b": "1" }, { "b": "2" } ] }' | jq -r '.a[0].b' 1 But if I try to get the values of all the b elements ...
user avatar
  • 1,151
0 votes
2 answers
91 views

API call for JSON to variable using SHELL or Python

I have an API access to a url that looks a little like this: curl https://api_url.com/device_groups/ -u api_key: Which outputs in JSON: { "data":[ { "type":"...
user avatar
-1 votes
2 answers
57 views

building a json from jq

I want to generate a json file in jq like this below : { "cpe": "dabb8fbd-d7be-4175-abb4-c628bb8cf1b5", "ps": [ "Obev" ], "ets": 5, "pMap&...
user avatar
  • 17
1 vote
4 answers
2k views

creating a nested json file from variables using jq

I have a script where I am storing variables and using that I am trying to create a json output to a file. here is my json build format #!/bin/bash JSON_STRING=$(jq -n \ --arg ...
user avatar
  • 17
0 votes
3 answers
116 views

Search for pattern and create file with the same name

Here's a simple line of my usage: grep -i '"location_country":"country name"' file.txt >> sample.txt I'm searching a large file with multiple countries and what I would like ...
user avatar
  • 13
0 votes
1 answer
77 views

less a file with JSON rows - how to highlight/colorize the rows?

I have log files with json rows inside - less displays it as just plain text Can I colorize the output with less abilities? As well as I didn't find any less-compatible third party tool with json ...
user avatar
1 vote
0 answers
57 views

echo unescaping quotes causing formatting errors

I'm using bash with jq to parse some json objects, some of these objects have double quotes in their descriptions which are escaped with backslashes: { "title": "foo" "...
user avatar
0 votes
1 answer
116 views

Parse lsblk with jq

I am currently trying to parse the output of lsblk with jq and filters it based on some criteria. Given the following example output: { "blockdevices": [ { "name":...
user avatar
  • 83
1 vote
3 answers
33 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":{"...
user avatar
  • 11
0 votes
2 answers
88 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&...
user avatar
3 votes
1 answer
1k 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 ...
user avatar
  • 165
2 votes
2 answers
112 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,"...
user avatar
  • 123
2 votes
3 answers
509 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 ...
user avatar
0 votes
1 answer
146 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 ...
user avatar

1
2 3 4 5
9