I am working with a JSON object named users
, which looks like this:
[{"givenName":"helen","sn":"brown","phone":"44512","details":"512"},{{"givenName":"John","sn":"Doe","phone":"44600","details":"512"}]
To convert this JavaScript object to a JSON string, I use the JSON.stringify
method. Then, I utilize the replace
function to replace the value 512
with active
. However, the issue is that this replacement affects all occurrences of 512
in the string. I specifically want to only apply this replacement on the values of the details
key, not on the entire string content (for instance, I do not want to alter the phone
value). How can I achieve this?