Skip to content

Instantly share code, notes, and snippets.

@mastef
Created July 11, 2018 11:52
Show Gist options
  • Save mastef/21288623c018fa2edec692adc6db66bf to your computer and use it in GitHub Desktop.
Save mastef/21288623c018fa2edec692adc6db66bf to your computer and use it in GitHub Desktop.
haxe json circular reference patch
var _data:Dynamic = ...;
var cache:Array<Dynamic> = [];
var jsonString = haxe.Json.stringify(_data, function(key:Dynamic, value:Dynamic) {
// kill keys you don't want here
// if(key == "ba") return null;
// only filter objects
if(value != null && Reflect.isObject(value)) {
if(cache.indexOf(value) > -1) {
return null;
}
// store value
cache.push(value);
}
return value;
});
js.Browser.window.console.log(jsonString);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment