You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm using rapidjson (great package, thank you!) to dump contents to a json file, and I use indent=0 to get a readable/diffable file.
However I have many tuples in my files, such as transformation matrices, and (though JSON has no tuple type) it would be nice to have them all on the same line instead of broken down, which makes the file harder tor ead and larger.
PyRJ cannot do that, because it defers almost every operation to the
underlying `RapidJSON` library, so you should ask them to know, sorry.
The problem I foresee is on how you could _drive_ the logic, I mean, it would
probably require additional parameters to say "ok, I want to split the
structure on multiple lines, except for arrays [at top level or at any depth?
all of them or only those shorter than a threshold? ...]".
Then one could ask "why restrict this to arrays? I'd like a similar compact
representation for objects too...".
You see, the thing could rapid-ly become complicated :-)
Anyway, I'm willing to expose the feature in PyRJ, if/when `RapidJSON`
implements it.
Thanks for the thoughts! It seems unlikely a JSON library would add support for "variable" indentation, so instead I chose to first make the string with all the newlines, and then find lists that contains simple elements (aka, no collections) and remove newlines within them.
One more idea, that may or may not be simpler than massaging the final output: if you have control on how the data in produced, you could preformat those tuples and wrap the result in RawJSON instances, and then call dumps() on the whole dataset...
Activity
lelit commentedon Apr 20, 2018
adrientetar commentedon Apr 20, 2018
Thanks for the thoughts! It seems unlikely a JSON library would add support for "variable" indentation, so instead I chose to first make the string with all the newlines, and then find lists that contains simple elements (aka, no collections) and remove newlines within them.
lelit commentedon Apr 20, 2018
One more idea, that may or may not be simpler than massaging the final output: if you have control on how the data in produced, you could preformat those tuples and wrap the result in
RawJSONinstances, and then calldumps()on the whole dataset...adrientetar commentedon Apr 20, 2018
Indeed that looks like it'd solve my problem efficiently, thanks!