JSON object inside object gets stringified incorrectly
Given the following request
POST https://test.com
{
"foo": {
"bar": "baz"
}
}
When I do <Plug>RestNvimPreview, it yields this:
curl -sSL --compressed -X 'POST' --data-raw '{"foo": "{\"bar\": \"baz\"}"}' 'https://test.com'
Notice how the value of foo becomes a string, even though it should be an object.
I expect the follwoing:
curl -sSL --compressed -X 'POST' --data-raw '{"foo": {"bar": "baz"}}' 'https://test.com'
I got the same issue. When trying to send an array, it would stringify the entire array. Took some time to finally find why it could not unmarshall the json :joy:
I had to read the code to find this out, but it will only properly serialize the JSON if you have Content-Type: application/json in your headers.
It seems like the rationale for this behavior is in https://github.com/rest-nvim/rest.nvim/pull/169#discussion_r1059405373
Essentially, JSON is special cased to minimize it and non-JSON is intended for form urlencoded but that seems like it's broken?
@thatsmydoing Content-Type: application/json seems to solve the issue like you said, however it feels redundant to have to specify that every time.
One solution would be to use Treesitter to determine the content of the body. When doing :TSPlaygroundToggle on my original example, Treesitter tells me that the body is a json_body.