This makes it really easy to create typedefs for data transferred as json.
Of course, not all json works well with this approach. The script
doesn't try to fix valid json that becomes invalid haxe object fields,
such as fields named "1foo", or "$#@$". The compiler will throw an
error for these.
The script handles all the basic types: Strings, Floats, Ints, and
Bools. It even tries to create typedefs recursively for child objects. The
script doesn't always make the right decisions for these typedef names,
since it has to infer the type from the field name that references it.
In some cases, the same name is found more than once. In that case,
the script will add "X" to the duplicate name until it finds a unique
name. The script will also not be able to detect duplicate instances of
the same json object structure (e.g., to give all these consistent
structures the same type name). However, it won't create duplicates
with arrays of objects. Instead, it only creates one definition based
on the first element in the array. Also, the script will always call
its top level object "JsonHxDef".
The script is pretty raw, but handles most of my needs at the
moment. If you find it useful, find some bugs, or want to suggest some
improvements, let me know. You invoke the script by calling: ./jsonhxdef test.json
the typedefs are written to stdout