One of the fields in my table has the JSON type so inside the model to save string there I need to do something like:
create(modifications: string.to_json,
...
)
to display this on the view the modifications column is parsed by JSON.parse which gives me the error 784: unexpected token at '"test registrant history"'
Long story short:
2.4.5 :042 > json_test = 'testing the string'.to_json
=> "\"testing the string\""
2.4.5 :043 > JSON.parse(json_test)
JSON::ParserError: 784: unexpected token at '"testing the string"'
why is this happening? how do you make JSON from a string then?
[Edit]
I'm on Rails 5 and Ruby 2.4.5
to_jsonit will be a simple string. I know json EOD is also string but formatting is different:"\"test note\""vs"test note". There is one similarity - the error is the same for both after JSON.parse784: unexpected token atJSON.parse("\"testing the string\"")works for me.