My Grape API accepts json format and I have method that accepts JSON as parameter:
desc 'JSON test'
params do
requires :json, type: JSON
end
post :json_test do
json = params[:json]
{result: json}
end
When I make request via postman, parameters are raw with application/json content type:
{
"json": {"test": "test"}
}
When I send this I get error message:
"json is invalid"
However, when I send it like this:
{
"json": "{\"test\": \"test\"}"
}
It shows me correct response:
{
"result": {
"test": "test"
}
}
Why this is happening? When I make type Hash
the first variant works, but if I want to send Array
of hashes/jsons? I kniw that Grape does not support Array[Hash]
type.