json

How to use jq to get a value from two possible paths?

How to use jq to get a value from two possible paths? I wanted to use jq to get a specific value b from two possible paths (and these two only). So, basically, I wanted to say jq ‘(path1 OR path2) | .b’ which should work if b is at one of the two paths …

Total answers: 1

JQ returns json lines without commas

JQ returns json lines without commas To be clear – I want a pseudo-JSON output that will be written into another static JSON file here… so not wrapped in an array or anything, simply getting the missing commas after each entity in my output. Currently my query is: .[] | select(.auditId == "categories") | { …

Total answers: 2

How to add content to a file before the last } character using Busybox utilities?

How to add content to a file before the last } character using Busybox utilities? There is a file with contents { "first_name": "John", "last_name": "Smith", "is_alive": true, "age": 27, "address": { "street_address": "21 2nd Street", "city": "New York", "state": "NY", "postal_code": "10021-3100" }, "phone_numbers": [ { "type": "home", "number": "212 555-1234" }, { "type": …

Total answers: 5

jq expression to merge

jq expression to merge I have the below JSON document from the Junos REST API. I am trying to simplify the document down to just a select few items. How would I accomplish this? Expected JSON: [ { "status": .member-status[0].data, "serial": .member-serial-number[0].data, "slot": .fpc-slot[0].data }, … ] Original JSON: { "member-status": [ { "data": "Prsnt" …

Total answers: 1

bash var substitution inside json to use in curl

bash var substitution inside json to use in curl Team, I am unable to substitute values inside json(myjson) to use in curl command. any hint? JENKINS_USERNAME="svc-user" JENKINS_USER_TOKEN="xxxx" JENKINS_INSTANCE_FQDN="sham.blsm.comp.com" INSTANCE="test-verify" CREDENTIAL_ID_NAME="test" USERNAME_KEY="tests" USER_PASSWORD_KEY="testst" ID_DESCRIPTION="asdfasdfasdf" myjson=”{ "credentials": { "scope": "GLOBAL", "id": "’"${CREDENTIAL_ID_NAME}"’", "username": "’"${USERNAME_KEY}"’", "password": "’"${USER_PASSWORD_KEY}"’", "description": "’"${ID_DESCRIPTION}"’", "$class": "com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl" } }” curl -X POST https://${JENKINS_USERNAME}:${JENKINS_USER_TOKEN}@${JENKINS_INSTANCE_FQDN}/${JENKINS_INSTANCE}/credentials/store/system/domain/_/createCredentials –data-urlencode …

Total answers: 2

Convert table to json

Convert table to json I have a large table of data that I would like to convert to json and am not sure if a tool like jq, mlr, or similar would be able to perform such a task without having to resort to my poor awk skills. Sample table: Balance_sheet for AAPL: 2023-09-30 2022-09-30 …

Total answers: 3

Search field and replace other in jq

Search field and replace other in jq I am trying to search for an object having a specific property and then update another property. Given this input: [ { "replacements": [ { "newValue": "0", "yamlPath": "k8s-helm-templates.deployment.containers.abc.image.tag" }, { "newValue": "0", "yamlPath": "k8s-helm-templates.deployment.containers.def.image.tag" }, { "newValue": "0", "yamlPath": "k8s-helm-templates.deployment.containers.ghi.image.tag" } ], "yamlFilePath": "k8s/helm/Dev/us-east-1/values.yaml" } ] and …

Total answers: 1

How to pass a single value argument to a JSON file from a script without overriding the existing values?

How to pass a single value argument to a JSON file from a script without overriding the existing values? I have the following JSON file named pool.json: { "AllocateActions": {}, "Available": true, "Description": "Pool for nodes in cluster – {{CLUSTER_NAME}}", "Endpoint": "", "EnterActions": { "AddProfiles": [ "{{RC_JOIN_PROFILE}}", "image-deploy-profile", "rc-controlplane-profile", "rc-etcd-profile" ], "Workflow": "rc-image-deploy" }, "Errors": …

Total answers: 1

Add/modify key/value in json object

Add/modify key/value in json object I’ve asked a similar question in the past but I’m having a hard time adapting that solution to this problem. I have the following json array: $ jq <<<"$json" [ { "id": "node1" }, { "id": "node2" }, { "id": "node3" } ] I want to add a key/value to …

Total answers: 1

Don't split at spaces in jq output

Don't split at spaces in jq output I used jq to convert an array of words into an argument for a java program. its like arguments=$(jq ‘.nameField | "-i " + """ + . + """’ file.json) java …. $arguments <– No quotes wrapped around arguments. Expected output: Java must read as -i "Name 1" …

Total answers: 3

How to convert a CSV with paragraphs to JSON on macOS's BSD Terminal?

How to convert a CSV with paragraphs to JSON on macOS's BSD Terminal? I have a huge text file that contains this structure: title;description;date The problem is that description main contain paragraphs, like: title;description;data MyText;Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam est dolor, molestie a rhoncus vel, congue sed diam. Vestibulum pellentesque libero …

Total answers: 1

Convert csv out of json in new coloumn

Convert csv out of json in new coloumn The below is my json code [ { "kind": "user", "version": "v2", "metadata": { "name": "person1" }, "spec": { "roles": [ "access", "auditor", "editor", "abc-access" ], "status": { "is_locked": false, "locked_time": "0001-01-01T00:00:00Z", "lock_expires": "0001-01-01T00:00:00Z", "recovery_attempt_lock_expires": "0001-01-01T00:00:00Z" }, "expires": "0001-01-01T00:00:00Z", "created_by": { "time": "2023-06-07T08:50:58.559675944Z", "user": { "name": "person2" …

Total answers: 1

Getting Error "{"errorMessages":["There was an error parsing JSON. Check that your request body is valid."]}

Getting Error "{"errorMessages":["There was an error parsing JSON. Check that your request body is valid."]} curl –request POST –url ‘https://bankofloyal.atlassian.net/rest/api/2/issue’ –user aditya.singh@lji.io:$JIRA_TOKEN –header ‘Accept: application/json’ –header ‘Content-Type: application/json’ –data ‘{ "fields": { "project": { "key": "’$JIRA_PROJECT’" }, "parent": { "key": "’$PARENT_ISSUE_KEY’" }, "components": [ { "id": "’$COMPONENT_ID’" } ], "summary": "Directories with migration changes: ‘"${DIR_JOINED}"’", …

Total answers: 2

Force Patch character differences to a file

Force Patch character differences to a file Hello, I have an englishStrings.json file and when I make new edits/ additions to it, I need to copy the new changes to all the other language string.json files. Before making any changes to englishStrings, the englishStrings and otherLanguageStrings have the same keys and same number of lines …

Total answers: 1

Convert json to csv with headers in jq

Convert json to csv with headers in jq Is it possible to convert this json: [ { "bytes": 276697, "checked": false }, { "bytes": 276697, "checked": false } ] to a table WITH headers in jq? I’ve tried: cat file.json | jq ‘.[] | join(",")’ but it omits headers: "276697,false" "276697,false" it should be: "bytes,checked" …

Total answers: 2

How to know a JSON array is an empty array in bash?

How to know a JSON array is an empty array in bash? I use this code to consume GitHub API and automate some tasks: curl –silent -H ‘Authorization: token github_access_token’ ‘https://api.github.com/orgs/OrganizationName/repos?per_page=100’ Sometimes I get this as the response: [ ] I want to know if the response is an empty array or not. I thought …

Total answers: 2

Forcing miller to read data as string in conversion to JSON

Forcing miller to read data as string in conversion to JSON In the following MWE echo x="1e2" | mlr –ojson cat my intention is for miller to generate a one-element JSON array containing the object {"x": "1e2"} The object actually returned (within the array) is instead {"x": 1e2} where the value is taken as a …

Total answers: 1

How to format a JSON string as a table using jq?

How to format a JSON string as a table using jq? I need to convert a JSON string using jq, as shown below, into a table format for displaying the output in the terminal. { "results": [ [ { "field": "@timestamp", "value": "2023-07-03 08:28:00.000" }, { "field": "CpuReserved", "value": "8192.0" }, { "field": "CpuUtilized", "value": …

Total answers: 4

Using jq to parse invalid JSON?

Using jq to parse invalid JSON? Can jq parse invalid JSON such as this?: [2023.06.07-21.58.47] StatManagerLog: { "RoundState": { "State": "Starting", "Timestamp": "2023.06.07-21.58.47" } } [2023.06.07-21.58.47] StatManagerLog: { "RoundState": { "State": "StandBy", "Timestamp": "2023.06.07-21.58.47" } } Ideally each StatManagerLog object would be read by jq. Cannot seem to find out how jq can do this. …

Total answers: 2

How to parse large files looking for a word

How to parse large files looking for a word I have some extremely large json files I am not even really sure if some are even written correctly Therefore viewing the with a editor is not possible (it freezes vscode etc) I can view them with less thefile.json but I am looking for (all) occurrences …

Total answers: 2