Skip to content

transform-it/json2dts

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Json2dts

Json2dts generates definition files for JSON like data.

Installation

npm install json2dts -g

Alternatively, a web-based version is available at http://xperiments.in/json2dts

Usage

Json2dts can be used either as a command-line application or as a Node.js module. To use the command-line version, invoke the json2dts command:

$ json2dts --help
Generates definition files for JSON like data.
Usage: json2dts file.json

Options:
  --output, -o     Specifies the file where to write the output
  --interface, -i  Specifies the main interface name
  --help           Show help                                           [boolean]

Examples:
  json2dts -i MainInterface file.json  Creates Typescript Definition file for the json file.json

To use the Node.js module:

var json2dts = require('./dist/json2dts');
var Json2dts = json2dts.Json2dts;
var toValidJSON = json2dts.toValidJSON;

var content='{point:[{x:0,y:0},{x:1,y:1}]}';

try {
    
    var converter = new Json2dts();
    var text2Obj = JSON.parse(toValidJSON(content));
    if (typeof text2Obj != "string") {
        converter.parse(text2Obj, 'RootJson');
        content = converter.getCode();
    }
    else {
        console.error('Json2dts Invalid JSON');
    }

} catch (e) {
    console.error('Json2dts Invalid JSON error:',e);
}

console.log( content );

About

Json2dts generates definition files for JSON like data.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 100.0%