Andres Andres - 1 year ago 95
JSON Question

Get a JSON as POST parameter

I have a ruby application and I need to receive a JSON from a client. Receiving a JSON is just like receiving a string? I just have to do something like:

information = params[:json_data]
data_parsed = JSON.parse(information)

That's all or I have to do something different when getting a JSON? The sender has to send me that like string?


jdl jdl
Answer Source

What you are describing is OK, but it implies that there is a param named json_data. If you instead mean that the entire POST body is nothing but the JSON, then you want to look at request.raw_post. You'd end up with something like this:

information = request.raw_post
data_parsed = JSON.parse(information)