0

I need to add a float field to a json, I'm doing somthing like :

echo '{"field":' '"value"}' | jq --arg id 21841453190106 --arg price 1.2 '.+ {$price}'

getting:

{
  "field": "value",
  "price": "1.2"
}

I'd like to have:

{
  "field": "value",
  "price": 1.2
}

thanks

EDIT: thanks to 0stone0 :

echo '{"field":' '"value"}' | jq --arg id 21841453190106 --argjson price 1 '.+ {$price}'

gives:

{
  "field": "value",
  "price": 1
}

any way to have

{
  "field": "value",
  "price": 1.0
}

?

Franco
  • 3
  • 2
  • use `--argjson` – 0stone0 Jul 05 '22 at 14:01
  • 1
    Does this answer your question? [How can I put integer as an argument in jq?](https://stackoverflow.com/questions/38752499/how-can-i-put-integer-as-an-argument-in-jq) – 0stone0 Jul 05 '22 at 14:01
  • 1
    wow, that was fast! Thanks, any way to have ".0",too ? echo '{"field":' '"value"}' | jq --argjson id 21841453190106 --argjson price 1 '.+ {$price}' { "field": "value", "price": 1 } "price":1.0 – Franco Jul 05 '22 at 14:02
  • Please see [this git issue](https://github.com/stedolan/jq/issues/1301), `1.0` is the same as `1` in number-land. If you provide eg `1.2` to `argjson` it wil keep the decimal places. – 0stone0 Jul 05 '22 at 14:24
  • 1
    once again, thanks. I see the point of 1.0 and 1 being the same, I would have needed this on the json receiver end, but I'll find other means to work this out. Thanks! – Franco Jul 05 '22 at 14:30

0 Answers0