elnabo / json2object

Type safe Haxe/JSON (de)serializer
MIT License
66 stars 17 forks source link

Support indentation in JsonWriter.write() #52

Closed Gama11 closed 5 years ago

Gama11 commented 5 years ago

Haxe's Json.stringify() supports an optional space parameter for formatted / indented output. json2object's JsonWriter seems to be lacking this feature.

I guess the same is true for JsonSchemaWriter, so far I've dealt with it simply by doing a Json.stringify(Json.parse(...), "\t") there.

elnabo commented 5 years ago

It should be done for JsonWriter. Since cc79ec2d54583a5fe74b6e160a080458af6854ee, it accept an indentation character as an optional argument.

I'm also working to add it for JsonSchemaWriter, but I didn't expect to touch that thing again, so it may take a while to have it works without breaking.

Gama11 commented 5 years ago

Awesome, thanks. :)

I guess in an ideal world, JsonSchemaWriter would actually use JsonWriter for writing? Although that may be difficult because of macro-in-macro...

elnabo commented 5 years ago

Yeah that is the current plan, to rewrite JsonSchemaWriter to generate an object that can be stringified by JsonWriter.

However, I don't think using JsonWriter in the schema macro would be a problem, as both JsonParser and JsonWriter are recursive macros.

elnabo commented 5 years ago

With cbb8ec4875fd158b0f942306024a761e05480329, indentation support has been added to the JsonSchemaWriter (via the constructor). Also an indentation bug with Array has been fixed.

Gama11 commented 5 years ago

Something's not quite right with indentation in arrays with struct literals:

elnabo commented 5 years ago

Should be fixed by a84680aa972f66fdf4278aad000696920ba9ea71.