Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve JSON output for Zed maps #4589

Merged
merged 1 commit into from
May 16, 2023
Merged

Improve JSON output for Zed maps #4589

merged 1 commit into from
May 16, 2023

Conversation

nwt
Copy link
Member

@nwt nwt commented May 11, 2023

In JSON output, a Zed map becomes an array of {"key":KEY,"value":VALUE} objects. Change that to a single object object whose keys are ZSON representations of the map keys, as in {"KEY":VALUE}.

  • String keys are used directly.
  • Non-string primitive keys are converted to undecorated ZSON.
  • Union keys are untagged and then converted to ZSON (with decoration for uniqueness).
  • Enum keys are converted to their corresponding symbol.
  • All other keys are converted to ZSON.

Closes #4567.

In JSON output, a Zed map becomes an array of {"key":KEY,"value":VALUE}
objects.  Change that to a single object object whose keys are ZSON
representations of the map keys, as in {"KEY":VALUE}.

* String keys are used directly.
* Non-string primitive keys are converted to undecorated ZSON.
* Union keys are untagged and then converted to ZSON (with decoration
  for uniqueness).
* Enum keys are converted to their corresponding symbol.
* All other keys are converted to ZSON.

Closes #4567.
@nwt nwt requested a review from a team May 11, 2023 00:33
@nwt
Copy link
Member Author

nwt commented May 11, 2023

I think this is probably what we want, but I'm definitely open to tweaking any of the key representations.

The one thing here I'm not sure about is floating point keys with integer values. Right now this converts them to, e.g., "1." because that's the ZSON representation, but we might want to make that "1.0".

@philrz
Copy link
Contributor

philrz commented May 11, 2023

Great ztests! It's just one person's opinion, but I'd be happy with what you've got it doing right now.

I'm not inclined to sweat the float keys too hard. FWIW, I've sometimes paused at the trailing dot in the ZSON output. Since we're converting to JSON, this seems maybe relevant:

$ echo '5. 5.0' | zq -j -
5
5

Which is to say it seems like we could drop with the dot altogether. But since in other logic you're converting to the ZSON equivalent then I could see why keeping the trailing dot would make it consistent because:

$ echo '5. 5.0' | zq -z -
5.
5.

If we decided the trailing .0 was desirable in the map-as-JSON output then it'd make me wonder why it's not just as desirable in the general ZSON output case.

Copy link
Collaborator

@mattnibs mattnibs left a comment

Choose a reason for hiding this comment

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

Lovely.

@nwt nwt merged commit a2626a7 into main May 16, 2023
@nwt nwt deleted the improve-JSON-output-for-maps branch May 16, 2023 18:05
@philrz philrz linked an issue May 25, 2023 that may be closed by this pull request
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.

Handling JSON-compatible pseudo-maps Improve JSON output of Zed map
3 participants