Skip to content

convert JSON of a specific format to a type structure(support Typescript type and Go type)

License

Notifications You must be signed in to change notification settings

hubvue/json2type

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

47 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

json2type

convert JSON of a specific format to a type structure(support Typescript type and Go type)

Quick Start

CLI

Install

use go tool install

go install github.com/hubvue/json2type/json2type@latest

use npm/yarn/pnpm install

# npm
npm install @cckim/json2type -g
# yarn
yarn global add @cckim/json2type
# pnpm
pnpm add @cckim/json2type --global

Usage

json2type help
Usage of json2type:
  -input string
    	the file of the json file(input parameter is required)
  -language string
    	used to convert json to the type of the language(typescript by default) (default "typescript")
  -name string
    	the name of the type name(auto by default) (default "auto")
  -output string
    	the name of the file to write the output to (outputs to stdout by default)
json2type -input=tmp.json
Example
{
  "name": "hubvue",
  "age": 18
}

Result:

interface Auto {
    name: string
    age: number
}

Package

go get github.com/hubvue/json2type

Usage

package main
import (
	"fmt"
	"github.com/hubvue/json2type"
)

func main() {
	fileJson, _ := ioutil.ReadFile(jsonFile)
	code, _ := json2type.Parser(fileJson, "typescript", "typeName")
	fmt.Println(code)
}

About

convert JSON of a specific format to a type structure(support Typescript type and Go type)

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

Packages

No packages published

Languages