Giter Club home page Giter Club logo

hxjsondef's Introduction

HxJsonDef

HxJsonDef is command-line app/macro/class written in Haxe that helps you quickly define a typedef from some arbitrary .json

I found a gist written in ruby that does the same (written by Justin Donaldson) and it inspired to write it in Haxe/Neko.

JSON Values

There are some rules you have to keep in mind. For the conversion it best NOT to use null as a value. It will be automatically converted to Dynamic, but if you know what the value will be; remove null and replace with one of the values described below.

JSON values can be:

  • A number (integer or floating point 1 / 1.1)
  • A string (in double quotes "....")
  • A Boolean (true or false)
  • An array (in square brackets [...])
  • An object (in curly braces {...})
  • null

https://www.w3schools.com/js/js_json_datatypes.asp

Haxelib

How to get this working?

You might want to update and/or correct the externs: install this repo locally

haxelib dev hxjsondef path/to/folder/src

Or use the developers version / cutting edge: this git repo

haxelib git hxjsondef https://github.com/MatthijsKamstra/hxjsondef

And don't forget to add it to your build file

-lib hxjsondef

Usage

You choose what works best for you:

Macro

Install the lib and add this to your build.hmxl

--macro hxjsondef.macro.AutomaticJsonDef.build('bin/example','src/ast')

First param is the source folder of the jsons, the second param is the "export" folder

Remember this is done every time you build. And the .hx are automaticly overwritten so any changes to that file are gone.

NOTE: this macro needs more love, so let me know what would work better.

Haxelib run

Install the lib and use your terminal to generate a .hx file based upon a .json file.

cd path/to/folder
haxelib run hxjsondef filename.json

And next to the filename.json there will be the converted ASTfilename.hx file.

You need to send the file you want to change. I might consider creating it for folders as well. Just let me know. Create an issue or a pull request.

neko

  • Download this repo
  • Open your terminal
  • cd to the correct folder (where hxjsondef is located: /hxjsondef/bin/)
neko hxjsondef /Volumes/path/to/foobar.json

And next to the foobar.json there will be the converted ASTfoobar.hx file.

See two json file converted in the example folder

class

Add lib to build.hxml

-lib hxjsondef

Example code

var str = '{
	"id": 1,
	"name": "A green door",
	"price": 12.50,
	"tags": ["home", "green"]
}';

var hxjsondef = new Hxjsondef();
hxjsondef.fileName = 'foo';
trace(hxjsondef.convert('foobar', str));

source

hxjsondef's People

Contributors

gama11 avatar matthijskamstra avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

hoseyjoe

hxjsondef's Issues

what to do with array json

[
    {
        "id": 1,
        "name": "a",
        "description": "aa"
    },
    {
        "id": 2,
        "name": "b",
        "description": "bbb"
    },
....

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.