I have a JSON object, and in the field resource_hours I want to store a JSON string.
{
"id": 4,
"resource": 1,
"resource_hours": "json goes here",
"start": "2009-10-10",
"end": "2010-10-10",
"created_at": "2017-06-01T13:23:06.103867Z",
"modified_at": "2017-06-01T13:23:06.103867Z"
}
Here is the string/object I want to store:
{
"winner": "john",
"loser": "not john"
}
I tried this:
"resource_hours": "{"winner":"john","loser":"not john"}"
but obviously that raised an error due to the overlapping double quotes.
I also tried using \ to escape the quotes like so:
"resource_hours": "{\"winner\":\"john\",\"loser\":\"not john\"}"
This worked (no error was raised), but is it still a JSON string/object? Can it still be parsed as a JSON object if pulled from a database using an API?
var obj = JSON.parse(<yourstring>)and thenobj.resource_hours = <value>