A plugin for lazy people who don't want to write types by hand. This plugin will convert JSON to various types based on the selected language.
- Neovim >= 0.8.0 (needs to be built with LuaJIT)
Added support for multiple languages. The list of supported languages is as follows:
- TypeScript
- JavaScript
- Python
- C#
- Go
- Rust
- PHP
- Ruby
- Swift
- Kotlin
- C++
- CJSON
- Crystal (cr)
- Dart
- Elixir
- Elm
- Flow
- Haskell
- Java
- JavaScript Prop Types
- Objective-C
- Pike
- Scala3
- Smithy
- TypeScript Zod
- TypeScript Effect Schema
- The commands
ConvertJSONtoTS
andConvertJSONtoTSBuffer
have been renamed toConvertJSONtoLang
andConvertJSONtoLangBuffer
respectively. Please update your keybindings and scripts accordingly.
Install the plugin with your preferred package manager:
{
"Redoxahmii/json-to-types.nvim",
build = "sh install.sh npm",
keys = {
{
"<leader>cu",
"<CMD>ConvertJSONtoLang typescript<CR>",
desc = "Convert JSON to TS",
},
{
"<leader>ct",
"<CMD>ConvertJSONtoLangBuffer typescript<CR>",
desc = "Convert JSON to TS in buffer",
},
},
}
- Provide your installer in the build command. Instead of
npm
, you can pass whatever you are using such asyarn
.
- To create keymaps for the language you want, you can refer to the method provided above or use it directly in command mode as well:
: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
- This will create a new file with the name
types-{filename}.{extension}
in the same directory as the file you are editing with type definitions. - Similarly, you can use the
ConvertJSONtoLangBuffer
command to create a new buffer with type definitions so you can make your changes immediately. - Supported languages are listed above for your reference.
- The reason for appending
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. - The base command has been renamed to
ConvertJSONtoLang
and the buffer command has been renamed toConvertJSONtoLangBuffer
. - You can also make keybindings for the mentioned commands by referring to the method provided above.
- Create a read-only buffer with the types.
- Support for other languages.
- Allow user to paste their API Link and get the types automatically.