A Neovim plugin designed to simplify the process of generating type definitions from JSON. This plugin supports multiple programming languages, making it a versatile tool for developers who want to save time and avoid manually writing type definitions.
Below is a list of the languages that are currently supported:
Install the plugin with your preferred package manager:
{
"Redoxahmii/json-to-types.nvim",
build = "sh install.sh npm", -- Replace `npm` with your preferred package manager (e.g., yarn, pnpm).
ft = "json",
keys = {
{
"<leader>cU",
"<CMD>ConvertJSONtoLang typescript<CR>",
desc = "Convert JSON to TS",
},
{
"<leader>ct",
"<CMD>ConvertJSONtoLangBuffer typescript<CR>",
desc = "Convert JSON to TS Buffer",
},
},
}
npm
, you can pass whatever you are using such as yarn
.:ConvertJSONtoLang typescript
:ConvertJSONtoLang javascript
:ConvertJSONtoLang python
:ConvertJSONtoLang csharp
:ConvertJSONtoLang go
:ConvertJSONtoLang rust
:ConvertJSONtoLang php
:ConvertJSONtoLang ruby
:ConvertJSONtoLang swift
:ConvertJSONtoLang kotlin
:ConvertJSONtoLang cpp
:ConvertJSONtoLang cjson
:ConvertJSONtoLang cr
:ConvertJSONtoLang dart
:ConvertJSONtoLang elixir
:ConvertJSONtoLang elm
:ConvertJSONtoLang flow
:ConvertJSONtoLang haskell
:ConvertJSONtoLang java
:ConvertJSONtoLang javascript-prop-types
:ConvertJSONtoLang objc
:ConvertJSONtoLang pike
:ConvertJSONtoLang scala3
:ConvertJSONtoLang Smithy
:ConvertJSONtoLang typescript-zod
:ConvertJSONtoLang typescript-effect-schema
types-{filename}.{extension}
in the same directory as the file you are editing with type definitions.ConvertJSONtoLangBuffer
command to create a new buffer with type definitions so you can make your changes immediately.Types-
before the file name is to avoid overwriting if there is an already existing .{extension}
file in the same directory with the same name.kulala.nvim
You can use this plugin with kulala.nvim to get the types automatically when you make a request to an API.
Here's an example of how you can make a keybinding for this:
{
"<leader>Rw",
function()
require("kulala.api").on("after_next_request", function(data)
local filename = "kulala.json"
local file = io.open(filename, "w")
if not file then
print("Error: Failed to open file for writing")
return
end
file:write(data.body)
file:close()
vim.cmd("edit " .. filename)
local buf = vim.api.nvim_get_current_buf()
vim.cmd("ConvertJSONtoLang typescript")
vim.api.nvim_buf_delete(buf, { force = true })
os.remove(filename)
end)
require("kulala").run()
end,
desc = "Toggle API Callback for JSON to TS Buffer",
},
You can replace typescript
with the language you want to use and this will acts as a toggle to ensure you can keep using your kulala.nvim
bindings as you've setup.
After one request, kulala.nvim
will default to it's own behavior.