I'm trying to write a json file as part of a neovim plugin I'm working on. I started with the code below.
Code:
write = function()
local json = vim.fn.json_encode("{\"test\": \"thing\"}")
print(json)
local ok, result = pcall(vim.fn.writefile, {json}, "./test.json")
if ok then
print("Okay")
else
print(result)
end
end
Output inside test.json:
"{\"test\": \"thing\"}"
This almost works, but as you can see it outputs a string. How can I properly get it to write as a JSON object?