I have an issue ahead of me and I am not sure even how to being approaching it.
The background is that I have a "record" coming from an API in a JSON string. This string is VERY dynamic and predicting the pair keys is almost impossible. BUT in the record there is always four fields, and these are the four I want to change.
In order to update the record the entire dataset must be sent back with the values you wish to update (Sending back only the fields I want to update results in all currently set fields being wiped out)
So my plan was, pull the JSON string, leave it in string format and then parse it to find the pairs that I want to change and then give the JSON string back to the API and magic! The fields won't be wiped.
So the issue I am facing is coming up with an idea of how to parse this string, find a key value "keyvalue1" and then updating its value "keyvalue1":"Update me"
This is a sample of the string I am working with: (The valuetobeupdated 1 - 4 and areas that need to be changed)
"{\"record\":
{\"status\":\"241\",
\"id\":\"a0de27a2-1447-4941-a3c0-8853e5682e85\",
\"created_by\":\"The Amazing Mongo\",
\"project_id\":null,
\"changeset_id\":\"eeba5ba9-8305-4cb3-ad63-6d1bbff6b626\",
\"valuetobeupdated1\":\"some long value needs to go in here\",
\"valuetobeupdated2\":\"more data is needed here\",
\"form_values\":
{\"833b\":\"00000\",
\"683b\":\"00000\",
\"62b2\":\"370\",
\"6472\":\"615\",
\"e4fa\":\"552\",
\"7868\":\"1\",
\"0d48\":\"4\",
\"1d54\":\"25\",
\"2155\":\"200\",
\"6435\":\"2\",
\"f4ad\":\"33\",
\"6c2b\":\"108\",
\"adb5\":\"62\",
\"e622\":\"0\",
\"d1f0\":\"25\",
\"8cf6\":\"0\",
\"80ad\":\"0\",
\"6fe4\":\"0\",
\"a148\":\"2016-05-13\",
\"6f55\":\"11:49\",
\"3b7c\":{\"choice_values\":[\"2409\"],
\"other_values\":[]},
\"valuetobeupdated3\":{\"choice_values\":[\"More information goes in here\"],
\"other_values\":[]
},
\"valuetobeupdated4\":{\"choice_values\":[\"more information here\"],
\"other_values\":[]
},
\"course\":null,}}"
So my question is how do I go about starting this, I have never been great at regular expressions and am not even sure if regex can do what I want to do here. The "Some long value needs to go here" and other values can be any length.
Any advice will be appreciated.