1

我有一个包含以下内容的 JSON 文件:-

{
  "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
}

我只想更新firstName的值。我想要的最终结果是

{
  "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
}

我试过这个

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

但没有成功。你能帮我吗?谢谢

4

1 回答 1

1

由于您想更新值,您将使用|=,并且不要忘记调用tojson

.content |= (fromjson | (.firstName = "abcdef") | tojson)
于 2020-11-11T13:54:33.277 回答