Skip to content

feat(json): pretty print#3255

Merged
lerno merged 3 commits into
c3lang:masterfrom
fernandolguevara:feat/json-pretty-print
May 28, 2026
Merged

feat(json): pretty print#3255
lerno merged 3 commits into
c3lang:masterfrom
fernandolguevara:feat/json-pretty-print

Conversation

@fernandolguevara
Copy link
Copy Markdown
Contributor

Add json pretty print

User user = { .username = "admin", .created_at = 611667900 };
String json = json::marshal(tmem, user, { .chars = "\t" });
assert(json == "{\n\t\"username\": \"admin\",\n\t\"created_at\": 611667900\n}");

Comment thread lib/std/encoding/json_marshal.c3 Outdated
import std::io;

struct Indent {
usz spaces;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better do this as an enum:

  1. No pretty print
  2. Tab
  3. 1 space
  4. 2 spaces
  5. 3 spaces
  6. 4 spaces
  7. 5 spaces

With no pretty print, don't add \n either.

@fernandolguevara fernandolguevara force-pushed the feat/json-pretty-print branch 3 times, most recently from 2198cc0 to 53e7c29 Compare May 25, 2026 14:46
@fernandolguevara fernandolguevara force-pushed the feat/json-pretty-print branch from 53e7c29 to 2333982 Compare May 26, 2026 13:30
@lerno lerno merged commit 83e16e4 into c3lang:master May 28, 2026
15 of 16 checks passed
@lerno
Copy link
Copy Markdown
Collaborator

lerno commented May 28, 2026

Thank you!

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

Successfully merging this pull request may close these issues.

2 participants