How to remove the quotes when reading a variable in jq in shell?

Given a JSON file, arguments.json:

{"dagger": true, "version": false, "nether_strike": true, 
 "greater_bash": "5", "FILE": "ancientscroll.txt", 
 "empower_haste": "1", "help": false}

When calling reading the variables as such:

#!/bin/bash
dagger=$(cat arguments.json | jq '.["dagger"]')
greater_bash =$(cat arguments.json | jq '.["greater_bash"]')    

echo $dagger
echo $greater_bash

[out]:

true
"5"

The variable contains the quotation marks "".

How to remove the quotes when reading a variable in jq?


I could use sed to strip the quotes as such:

greater_bash =$(cat arguments.json | jq '.["greater_bash"]' | sed -e 's/^"//' -e 's/"$//')
echo $greater_bash

[out]:

5

Leave a Comment