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
(void)emboss_reserved_local_wrote_field;
if (emboss_reserved_local_options.multiline()) {
if (emboss_reserved_local_wrote_field &&
emboss_reserved_local_options.json()) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You can delete the && ...json() here and then lines 348-351 entirely, I believe.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

That would break non-JSON multiline output, suggestion?

Comment thread compiler/back_end/cpp/generated_code_templates Outdated
Comment thread runtime/cpp/emboss_text_util.h Outdated
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.
- JsonLargeIntegerHandling::kLargeAsString optionally serializes integers
  wider than 32 bits as quoted strings, avoiding precision loss in JSON
  parsers that treat all numbers as IEEE-754 doubles.

Adds JsonTestEnum/JsonTestArrayStruct/JsonTestStruct fixtures to
testdata/text_format.emb and coverage in text_format_test.cc and
emboss_array_view_test.cc.  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