1

I have a JSON file with content this:-

{
  "content": "{\"accountNumber\":\"12345\",\"transactionId\":\"568\",\"socialSecurityNumber\":\"123456796\",\"identificationNumber\":1,\"securityCode\":\"1234\",\"dateOfBirth\":\"1000-01-01\",\"firstName\":\"qwerty\",\"lastName\":\"xyz\",\"balance\":123}",
  "contentType": "application/json",
  "createdAt": "2020-11-11T12:55:41.350+0000",
  "cryptoKeyId": null
}

I just want to update the value of firstName. End result I want is

{
  "content": "{\"accountNumber\":\"12345\",\"transactionId\":\"568\",\"socialSecurityNumber\":\"123456796\",\"identificationNumber\":1,\"securityCode\":\"1234\",\"dateOfBirth\":\"1000-01-01\",\"firstName\":\"abcdef\",\"lastName\":\"xyz\",\"balance\":123}",
  "contentType": "application/json",
  "createdAt": "2020-11-11T12:55:41.350+0000",
  "cryptoKeyId": null
}

I tried this

 ( .content | fromjson.firstName = "abcdef"  )

but no success. Can you help me here? Thanks

peak
  • 105,803
  • 17
  • 152
  • 177

1 Answers1

1

Since you want to update the value, you would use |=, and don’t forget the call to tojson:

.content |= (fromjson | (.firstName = "abcdef") | tojson)
peak
  • 105,803
  • 17
  • 152
  • 177
  • @mukeshyadav: If you feel satisfied with the answer, don't stop at saying Thanks. You show your gratitude by _accepting_ the answer (tick-mark near the answer). See [What should I do when someone answers my question?](https://stackoverflow.com/help/someone-answers) – Inian Nov 11 '20 at 17:33