Zum Hauptinhalt springen
tsecurity.de LIVE
Echtzeit-Radar & Feeds
Alle RSS Feeds
👥 Community & Social
Sichere ProgrammierungUmfrage: Wo drückt Sie der Schuh im Microsoft-Umfeld?(21.09.2026 um 12:00 Uhr)
Sichere ProgrammierungHow I Built (and Broke) a Production Multi-Agent AI System(21.09.2026 um 12:02 Uhr)
Sichere ProgrammierungResize and strip EXIF metadata from user uploads in Node.js(21.09.2026 um 12:04 Uhr)
Sichere ProgrammierungHandbrake Alternatives: What to Use When You Don't Want to Install It(21.09.2026 um 12:08 Uhr)
Sichere Programmierungwhy on earth does the Claude logo still look like a sphincter?(21.09.2026 um 12:08 Uhr)
Sichere ProgrammierungUmfrage: Wo drückt Sie der Schuh im Microsoft-Umfeld?(21.09.2026 um 12:00 Uhr)
Sichere ProgrammierungHow I Built (and Broke) a Production Multi-Agent AI System(21.09.2026 um 12:02 Uhr)
Sichere ProgrammierungResize and strip EXIF metadata from user uploads in Node.js(21.09.2026 um 12:04 Uhr)
Sichere ProgrammierungHandbrake Alternatives: What to Use When You Don't Want to Install It(21.09.2026 um 12:08 Uhr)
Sichere Programmierungwhy on earth does the Claude logo still look like a sphincter?(21.09.2026 um 12:08 Uhr)
Intelligence View
⚡ tsecurity.de Intelligence

Making Pretty-Printed JSON Readable Again in Python

Most JSON serializers give you only two choices: compact machine output: {"a":{"b":{"c":"abc"}},"x":{"y":{"z":"xyz"}}} or fully expanded “pretty-print”: { "a": { "b": { "c": "abc" } }, "x": { "y": { …

0
↗ Quelle (dev.to)
Reagiere als Erste:r — dein Feedback zählt!

Most JSON serializers give you only two choices:




  • compact machine output:




{"a":{"b":{"c":"abc"}},"x":{"y":{"z":"xyz"}}}







  • or fully expanded “pretty-print”:




{
"a": {
"b": {
"c": "abc"
}
},
"x": {
"y": {
"z": "xyz"
}
}
}






I wanted something in between: the first is hard for humans to scan, and the second becomes extremely verbose on real-world nested data.






The Idea



I wrote a small Python module called jsonfold. Instead of replacing Python’s JSON serializer, it works as a lightweight post-processing filter on top of json.dump() output.



The formatter selectively:




  • folds small containers back onto one line,

  • packs short scalar sequences,

  • keeps large or complex structures expanded.



Example output:




{
"a": { "b": { "c": "abc" } },
"x": { "y": { "z": "xyz" } }
}









Why This Approach?



I did not want to rebuild a serializer - there are many good serializers (including the built-in json.dump()) that can efficiently process anything from simple data structures (list/dict) to custom classes and Python @dataclass objects, perform transformations and customize the output layout.



The interesting part is that the formatter does not re-parse the JSON stream. It operates as a streaming wrapper around file-like objects:




json.dump(obj, JSONFoldWriter(fp), indent=2)






That means that it can handle large documents with fixed memory usage and linear processing time. This approach works with most existing serializers. It also provides wrappers for json.dump(), json.dumps().




from jsonfold import dumps

data = {
"a": {"b": {"c": "abc"}},
"x": {"y": {"z": "xyz"}},
}

print(dumps(data))









Customization



The formatter allows controlling:




  • maximum line width,

  • folding depth,

  • packing aggressiveness,

  • array/object limits.



So you can choose between conservative formatting and more aggressive compaction.






Full Article:



Medium (no paywall): A Streaming JSON Formatter That Works With Existing Serializers






Minimal Usage



Pull jsonfold.py from GitHub project




import jsonfold
import sys
data = {
"meta": {"version": 1, "ok": True},
"ids": [1, 2, 3, 4, 5],
"items": [{"id": 1, "name": "alpha"}, {"id": 2, "name": "beta"}],
}
# compact can be: default, low, med, high, max
jsonfold.dump(data, sys.stdout, compact="default")










GitHub Project



Repository: https://github.com/yairlenga/jsonfold



Python implementation is under python directory.



Future articles will cover other implementations: JavaScript, Java, C, ... - please watch the GitHub project, or follow the articles on Medium.

Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Making Pretty-Printed JSON Readable Again in Python

Thematisch verwandte Begriffe: Making, PrettyPrinted, JSON, Readable · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Zum Aktualisieren ziehen
ZERO-DAY CVE-2026-94040 | A flaw has been found in vas3k TaxHacker up to 0.8.5. Affected by this v…
Advisory →
TTS Reader • tsecurity.de Voice
tsecurity.de Icon
tsecurity.de App
Offline-Lesen, Eilmeldungen & 0ms Ladezeit

Installiere tsecurity.de direkt auf deinen Home-Bildschirm für das ultimative Vollbild-Magazinerlebnis ohne Browser-Leisten.

Nächster Beitrag
Themen-Radar & Intelligence Matrix
Echtzeit-Taxonomie nach Angriffsvektoren & Plattformen

tsecurity.de Live Threat Radar

🔴 LIVE RADAR
MONITORING
AKTIV
CVE-DATENBANK
LIVE
🔍
Community Radar & Live Chat
Sentinel Bot online • Live-Stream
Dein Cluster: Security Explorer
Match:
lädt…
Verbindung zum Community-Stream wird aufgebaut...
Bearbeitungsmodus — Senden überschreibt deine Nachricht
Community-Puls — was gerade passiert
lädt…
Aktivitäten deiner Analysten
lädt…
Neues Thema oder Eilmeldung einreichen

Reiche interessante Links, Zero-Days oder Debatten ein. Die Community entscheidet per Upvote über die Veröffentlichung.

Heiß diskutierte Einreichungen
🔖 Gespeicherte Artikel
📂 Keine gespeicherten Artikel vorhanden.
Zurück Ziehen Vor
Links: vorheriger Artikel Rechts: nächster Artikel unten: schließen
News NIS-2 Frühwarnung Tier-1 Intel ⏱️ 3 Min vor 10 Min
Artikeldaten werden geladen...

Zurück: vorheriger Vor: nächster
↗ Original-Quelle
Social Reaktionen Deine Reaktion zählt
Einstufung & Relevanz-Poll 0 Stimmen
In sozialen Netzwerken teilen 1-Klick