Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

indentation !=0 & suppress line feed between array elements in JSON output #286

Open
RalphSteinhagen opened this issue Aug 24, 2020 · 0 comments

Comments

@RalphSteinhagen
Copy link

Thanks for the great library. This fits our use-case quite neatly and has a great IO performance. 馃憤

As food-for-thought and/or possible feature request linked to the JsonStream.setIndentionStep(DEFAULT_INDENTATION) config.

Would it be possible to suppress line feeds (return) between individual array elements and add the line-feed only once the array is complete? Presently (e.g. JsonStream.setIndentionStep(DEFAULT_INDENTATION)) e.g.:

{
  "bool1": true,
  "byte1": 10,
  "char1": 97,
  "short1": 20,
  "int1": 30,
  "long1": 40,
  "float1": 50.5,
  "double1": 60.6,
  "string1": "\u0393\u03b5\u03b9\u03ac \u03c3\u03bf\u03c5 \u039a\u03cc\u03c3\u03bc\u03b5!",
  "boolArray": [
    true,
    false,
    true,
    false,
    true,
    false,
    true,
    false,
    true,
    false
  ],
  "doubleArray": [
    0.699999988079071,
    0.800000011920929,
    0.8999999761581421,
    1.0,
    1.100000023841858,
    1.2000000476837158,
    1.2999999523162842,
    1.399999976158142,
    1.5,
    1.600000023841858
  ]
}

to something like:

{
  "bool1": true,
  "byte1": 10,
  "char1": 97,
  "short1": 20,
  "int1": 30,
  "long1": 40,
  "float1": 50.5,
  "double1": 60.6,
  "string1": "\u0393\u03b5\u03b9\u03ac \u03c3\u03bf\u03c5 \u039a\u03cc\u03c3\u03bc\u03b5!",
  "boolArray": [true, false, true, false, true, false, true, false, true, false],
  "doubleArray": [0.699999988079071, 0.800000011920929, 0.8999999761581421, 1.0, 1.100000023841858, 1.2000000476837158, 1.2999999523162842, 1.399999976158142, 1.5, 1.600000023841858]
}

This has no impact on the validity or numeric parsing of the JSON output but (similarly to the indentation) would make it more human-readable, especially for large arrays, large maps, and if there are many fields.

N.B. as a minor side note/question: isn't the double format more precise/faster if expressed in an exponential form (am thinking since IEEE floating points are stored w.r.t. exponent and mantissa)

I see the place in the code where the line feed is issued to the stream but the corresponding function/array reflection handlers cannot be overwritten. Thanks in advance and keep up the good work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant