-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
print primitive array in single line or set a line width for primitive array object #2754
Comments
This might not work that reliably; A line width could work, but probably rather as "soft" limit, so once it has been reached or exceeded the next value is written in the next line. If it was a hard limit, the writer would have to look ahead how large the next value will be or write it to a temporary buffer first before being able to decide if it has to be wrapped into the next line. Would be interesting to see if and how other JSON libraries support this, maybe even in programming languages other than Java. (These were just some personal thoughts on this proposal, not any specific plans to implement this yet.) |
Hey Can I work on this issue:) |
Thanks for your offer @dhrax21! Based on my previous #2754 (comment), I think there are currently a few open questions; maybe this needs further feedback from @frankfliu. But what you could do, if you want, is research if / how other popular JSON libraries (for Java, but possibly also other programming languages) support this, and then document it here, including the cases where popular JSON libraries don't support it (linking to feature requests, in case there are any). That would help better understand how commonly needed this feature is, and what good approaches for implementing this could be. However, there is no guarantee that this feature will be implemented in the end. So no worries if you are not interested then in investigating this. |
My use case is pretty simple, I want to serialize a json object than contains a image or tensor (multidimensional array). The sensor size is pretty big (like 3x1024x768), I'd like to have a semi-readable serialized format. Currently using |
I have a few other proposals:
|
Thanks for the references!
I also found these:
|
That will probably not be possible. JSON writing and pretty-printing happens in
Maybe that could indeed be a solution, or something similar to what you originally proposed above:
So not disable array pretty-printing in general, but based on its content (or based on the first value). My comment #2754 (comment) might have been a bit too pessimistic. Assuming that the majority of JSON arrays contains values of the same type, such an option might work well. It would be opt-in anyway, so for arrays of mixed types we could document that the exact formatting is undefined. (These are just my personal thoughts on this though.) |
Problem solved by the feature
When json object contains a large
int[]
orint[][]
object, the pretty print is not useable. each element ends with newline.Feature description
We should have an option in
FormattingStyle
to serialize primitive array in a single line (or even better configurable line width)Alternatives / workarounds
The text was updated successfully, but these errors were encountered: