Skip to content

Add JSON output support to Emboss text format#237

Open
AaronWebster wants to merge 1 commit into
masterfrom
text-output-json
Open

Add JSON output support to Emboss text format#237
AaronWebster wants to merge 1 commit into
masterfrom
text-output-json

Conversation

@AaronWebster

Copy link
Copy Markdown
Collaborator

Add JSON output support to Emboss text format

Comment thread compiler/back_end/cpp/generated_code_templates
Comment thread compiler/back_end/cpp/generated_code_templates
Comment thread compiler/back_end/cpp/generated_code_templates Outdated
Comment thread compiler/back_end/cpp/generated_code_templates Outdated
Comment thread compiler/back_end/cpp/testcode/text_format_test.cc Outdated
Comment thread compiler/back_end/cpp/generated_code_templates
Comment thread compiler/back_end/cpp/generated_code_templates Outdated
Comment thread runtime/cpp/emboss_text_util.h Outdated
@AaronWebster
AaronWebster force-pushed the text-output-json branch 3 times, most recently from f3d6098 to b74c57e Compare July 16, 2026 23:33
Add a `json` mode to TextOutputOptions so any view can be serialized as
JSON, e.g. `WriteToString(view, TextOutputOptions().Json(true))`:

- Field names are quoted and values are comma-separated; comments are
  suppressed.  Compact output by default; multiline JSON places each
  field on its own indented line.
- Enums serialize as quoted names (or bare numbers when the value has no
  name); bool as true/false; NaN and Infinity as quoted strings.
- comments(), digit_grouping(), and numeric_base() automatically return
  JSON-appropriate values when json() is set, so callers don't have to
  special-case JSON throughout.
- Integers wider than 32 bits -- and the numeric form of unnamed enum
  values whose underlying type is wider than 32 bits -- are serialized as
  quoted strings by default (JsonLargeIntegerHandling::kLargeAsString),
  avoiding silent precision loss in JSON parsers that treat all numbers as
  IEEE-754 doubles.  JsonLargeIntegerHandling::kAsNumber opts back into raw
  numeric output for consumers that preserve full 64-bit integers.

Adds JsonTestEnum/JsonTestArrayStruct/JsonTestStruct/JsonEnumStruct/
JsonFloatStruct fixtures to testdata/text_format.emb and coverage in
text_format_test.cc and emboss_array_view_test.cc (compact and multiline
output, skipped fields, large-integer and unnamed-enum handling, and
NaN/Infinity).  Regenerates the C++ goldens.
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