Skip to content

Commit 46441b6

Browse files
committed
fix: parsing of nested tables in request body
1 parent 744bd43 commit 46441b6

File tree

2 files changed

+17
-16
lines changed

2 files changed

+17
-16
lines changed

lua/rest-nvim/config/init.lua

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,15 @@ local config = {
1515
formatters = {
1616
json = "jq",
1717
html = function(body)
18-
return vim.fn
19-
.system({
20-
"tidy",
21-
"-i",
22-
"-q",
23-
"--tidy-mark",
24-
"no",
25-
"--show-body-only",
26-
"auto",
27-
"--show-errors",
28-
"0",
29-
"--show-warnings",
30-
"0",
31-
"-",
32-
}, body)
33-
:gsub("\n$", "")
18+
-- stylua: ignore
19+
return vim.fn.system({
20+
"tidy", "-i", "-q",
21+
"--tidy-mark", "no",
22+
"--show-body-only", "auto",
23+
"--show-errors", "0",
24+
"--show-warnings", "0",
25+
"-",
26+
}, body):gsub("\n$", "")
3427
end,
3528
},
3629
},

lua/rest-nvim/request/init.lua

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,18 @@ local function get_body(bufnr, start_line, stop_line, has_json)
7272
end
7373

7474
local is_json, json_body = pcall(vim.fn.json_decode, body)
75+
7576
if is_json then
7677
if has_json then
78+
-- convert entire json body to string.
7779
return vim.fn.json_encode(json_body)
7880
else
81+
-- convert nested tables to string.
82+
for key, val in pairs(json_body) do
83+
if type(val) == "table" then
84+
json_body[key] = vim.fn.json_encode(val)
85+
end
86+
end
7987
return json_body
8088
end
8189
end

0 commit comments

Comments
 (0)