Skip to content

Instantly share code, notes, and snippets.

@ibilon
Last active January 28, 2021 11:31
Show Gist options
  • Save ibilon/db1e3a6cb3836b75c356421e013a35e3 to your computer and use it in GitHub Desktop.
Save ibilon/db1e3a6cb3836b75c356421e013a35e3 to your computer and use it in GitHub Desktop.
Haxe compile time json
> haxe --main Main --interpfinal a = compileJson("test.json");
Main.hx:8: {hello: world, obj: {sub: 0.3}, count: 7}
Main.hx:10: {hello: world, obj: {sub: 1.3}, count: 7}
class Main {
macro static function compileJson(path:String) {
return haxe.macro.Context.parseInlineString(sys.io.File.getContent(path), haxe.macro.Context.currentPos());
}
static function main() {
final a = compileJson("test.json");
trace(a);
a.obj.sub += 1;
trace(a);
}
}
{
"hello": "world",
"count": 7,
"obj": {
"sub": 0.3
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment