Sorry in advance for not including a working example. Hoping if someone is aware of the issue and can answer without a working example.
I have a struct, say
struct User JSON.mapping( name: String?, email: String, hobbies: Array(String)? ) end
I make a json post request from the client to the server (a route in Kemal) that contains the user’s information. Option 1 below fails, while option 2 works. Any ideas why Option 1 is failing? Why do I have to do
JSON.parse(postbody).to_json for it to work. I am worried that the solution may not be robust. Would really appreciate any help.
Option 1 (errors out with: Unexpected token: EOF at 1:1)
postbody = env.request.body.not_nil! user = User.from_json(postbody)
Option 2 (this works)
postbody = env.request.body.not_nil! modpostbody = JSON.parse(postbody).to_json user = User.from_json(postbody)