Skip to content

JSON: Implement printing for all types#8701

Merged
kripken merged 3 commits into
WebAssembly:mainfrom
kripken:json2
May 14, 2026
Merged

JSON: Implement printing for all types#8701
kripken merged 3 commits into
WebAssembly:mainfrom
kripken:json2

Conversation

@kripken
Copy link
Copy Markdown
Member

@kripken kripken commented May 14, 2026

Also add minor quality-of-life improvements like nicer constructors.

This will be enough to print out JSON easily for fuzzing.

@kripken kripken requested a review from tlively May 14, 2026 16:03
@kripken kripken requested a review from a team as a code owner May 14, 2026 16:03
Comment thread src/support/json.cpp Outdated
Comment on lines +35 to +36
// TODO: Use wtf16.view() once we have C++20.
wasm::String::printEscapedJSON(os, wtf16.str());
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We have C++20 now!

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done, before I just moved this around without reading...

Comment thread src/support/json.cpp Outdated
Comment on lines +49 to +52
if (pretty) {
os << '\n';
doIndent();
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe it's worth pulling out this snippet into a newLine() helper?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Good idea, done.

Comment thread src/support/json.h
explicit Value(const char* s) : type(Null) { setString(s); }
explicit Value(const std::string& s) : type(Null) { setString(s.c_str()); }
explicit Value(const std::string_view& s) : type(Null) {
setString(std::string(s));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
setString(std::string(s));
setString(s.data());

This seems like it does the same thing a little more directly.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Hmm, but the data is not null-terminated?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Oh right. Never mind then.

@kripken kripken merged commit 02f114b into WebAssembly:main May 14, 2026
16 checks passed
@kripken kripken deleted the json2 branch May 14, 2026 19:58
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