Skip to main content
Fixed broken formatting.
Source Link

To add a property to a JSON text I manage to use

result=$(jq -c '.docs[0] + { "value": "someValue" }'<<<"$fileContent")

But if I want to replace "someValue" by a variable:

result=$(jq -c '.docs[0] + { "value": ($value) }'<<<"$fileContent")

This gives me

jq: error: value/0 is not defined at , line 1:
.docs[0] + { "value": ($value) }
jq: 1 compile error

jq: error: value/0 is not defined at <top-level>, line 1:
.docs[0] + { "value": ($value) }
jq: 1 compile error

I also tried without braces $value and inside brackets [$value] without success.

To add a property to a JSON text I manage to use

result=$(jq -c '.docs[0] + { "value": "someValue" }'<<<"$fileContent")

But if I want to replace "someValue" by a variable:

result=$(jq -c '.docs[0] + { "value": ($value) }'<<<"$fileContent")

This gives me

jq: error: value/0 is not defined at , line 1:
.docs[0] + { "value": ($value) }
jq: 1 compile error

I also tried without braces $value and inside brackets [$value] without success.

To add a property to a JSON text I manage to use

result=$(jq -c '.docs[0] + { "value": "someValue" }'<<<"$fileContent")

But if I want to replace "someValue" by a variable:

result=$(jq -c '.docs[0] + { "value": ($value) }'<<<"$fileContent")

This gives me

jq: error: value/0 is not defined at <top-level>, line 1:
.docs[0] + { "value": ($value) }
jq: 1 compile error

I also tried without braces $value and inside brackets [$value] without success.

To add a property to a JSON text I manage to use

result=$(jq -c '.docs[0] + { "value": "someValue" }'<<<"$fileContent")

But if I want to replace "someValue" by a variable:

result=$(jq -c '.docs[0] + { "value": ($value) }'<<<"$fileContent")

This gives me

result=$(jq: error: value/0 is not defined at <top-level>, linec 1:
'.docs[0] + { "value": ($value) }
jq: 1 compile error'<<<"$fileContent")

This gives me

jq: error: value/0 is not defined at , line 1:
.docs[0] + { "value": ($value) }
jq: 1 compile error

I also tried without braces $value and inside brackets [$value] without success.

I'm new with to scripting, Thank's for further help!

To add a property to a JSON text I manage to use

result=$(jq -c '.docs[0] + { "value": "someValue" }'<<<"$fileContent")

But if I want to replace "someValue" by a variable:

result=$(jq -c '.docs[0] + { "value": ($value) }'<<<"$fileContent")

This gives me

jq: error: value/0 is not defined at <top-level>, line 1:
.docs[0] + { "value": ($value) }
jq: 1 compile error

I also tried without braces $value and inside brackets [$value] without success.

I'm new with to scripting, Thank's for further help!

To add a property to a JSON text I manage to use

result=$(jq -c '.docs[0] + { "value": "someValue" }'<<<"$fileContent")

But if I want to replace "someValue" by a variable:

result=$(jq -c '.docs[0] + { "value": ($value) }'<<<"$fileContent")

This gives me

jq: error: value/0 is not defined at , line 1:
.docs[0] + { "value": ($value) }
jq: 1 compile error

I also tried without braces $value and inside brackets [$value] without success.

edited tags
Link
Gilles 'SO- stop being evil'
  • 865.3k
  • 205
  • 1.8k
  • 2.3k
deleted 9 characters in body
Source Link
MHogge
  • 237
  • 2
  • 5
  • 10
Loading
Source Link
MHogge
  • 237
  • 2
  • 5
  • 10
Loading