Skip to content

MatthijsKamstra/hxjsondef

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

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

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages