json2type

package module
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 19, 2021 License: MIT Imports: 5 Imported by: 0

README

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 output.[ext] by default) (default "output")
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)
	// currently only typescript is supported
	code, _ := json2type.Parser(fileJson, "typescript", "typeName")
	fmt.Println(code)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run added in v0.2.0

func Run(input []byte, language string, name string) (string, error)

Run resolve JSON to the type of the corresponding language

input: JSON data
language: type lang
name: outermost layer typeName

Types

This section is empty.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL