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.

How to pretty print data class?

See original GitHub issue

I have some code like this:

data class MyClass(val list: List<String>, i: Int)
val obj = MyClass(listOf(), 1)
Klaxon().toJsonString(obj)

However, this results in a string without any whitespace or formatting. Is there another call that applies formatting to the output string? The readme recommends JsonObject.toJsonString(), but I cant find any way to turn my object into a JsonObject with klaxon.

What is the correct way to do this?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:12 (2 by maintainers)

github_iconTop GitHub Comments

14reactions
MeLlamoPablocommented, Sep 9, 2018

@camdenorrb +1

It would be nice to have

Klaxon().toJsonString(obj, prettyPrint = true)
6reactions
camdenorrbcommented, Aug 1, 2018

Why do you first have to convert it to a String… And then parse it…

Read more comments on GitHub >

github_iconTop Results From Across the Web

Pretty-print dataclasses prettier - python - Stack Overflow
Basically I'm looking for a way to customize the default dataclasses string representation routine or for a pretty-printer that understands data ...
Read more >
pprint — Data pretty printer — Python 3.11.1 documentation
The pprint module provides a capability to “pretty-print” arbitrary Python data structures in a form which can be used as input to the...
Read more >
Kotlin: pretty print data classes - DEV Community ‍ ‍
The only little trick worth mentioning is that I first call toString() on the data class, and extract all properties present in the...
Read more >
Prettify Your Data Structures With Pretty Print in Python
The pprint module in Python is a utility module that you can use to print data structures in a readable, pretty way. It's...
Read more >
Pretty printing dataclasses · Discussion #891 · Textualize/rich
Is there an automatic-ish way to get black-like spacing for the output of a data class, without going member by member with something...
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