Andres Andres - 1 month ago 5x
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

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)