question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

PrettyPrinter Indenter: Ability to insert eol before object and array entries

See original GitHub issue

I’d like to be able to configure an indenter to insert a newline before object and array braces/brackets. Instead of:

{
  foo: {
    bar: true
  }
}

I want:

{
  foo:
  {
    bar: true
  }
}

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
cowtowncodercommented, Sep 21, 2015

No, this will not work and is not intended to work. Indenter is valid within context of an open JsonGenerator, and one will be constructed for each writeValueAsString. ObjectWriters are stateless, immutable, and there is no way (or intent) to share state of indenter.

To produce root value separators, a single JsonGenerator must be used, as that tracks output state, to know where and when to add root value separator.

0reactions
cowwoccommented, Sep 20, 2015

I think the problem is that ObjectWriter.writeValueAsString() creates a nested writer per invocation, so rootValueSeparator is never triggered (it only sees us writing a single value each time). To clarify: I need a way to “clean up” the pretty printer at the beginning or end of each writeValueAsString() invocation. I don’t see a way to do that with the current API.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Jackson JSON Deserialization: array elements in each line
I am using Jackson and would like to pretty-print JSON such that each element in arrays goes to each line ...
Read more >
PrettyPrinter (Jackson-core 2.6.0 API) - FasterXML
Interface for objects that implement pretty printer functionality, such as indentation. Pretty printers are used to add white space in output JSON content, ......
Read more >
IO tools (text, CSV, HDF5, …) — pandas 1.5.2 documentation
The Python engine loads the data first before deciding which columns to drop. ... string values from the columns defined by parse_dates into...
Read more >
How to Prettify Data Structures with Pretty Print in Python
The dictionary is now an array. The next step is printing the contents using print().
Read more >
Groovy Language Documentation
You will notice that the resulting string contains a newline character as first ... Groovy classes must specify their package before the class...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found