Skip to content

[known issue] omitempty or not? #7

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

Closed
jmnote opened this issue Jul 7, 2024 · 1 comment
Closed

[known issue] omitempty or not? #7

jmnote opened this issue Jul 7, 2024 · 1 comment
Assignees

Comments

@jmnote
Copy link
Owner

jmnote commented Jul 7, 2024

Should we use omitempty for optionals or not?

  1. optional in the nbformat spec and omitempty
  • metadata.kernelspec.language
  • cell.execution_count

If the original JSON contains these keys with empty strings ("") or null values, the keys and values will be omitted in the result due to omitempty.

  1. optional in the nbformat spec, but NOT omitempty
  • cell.outputs

outputs in cells are optional, but sometimes we also want the outputs to be empty slices ("outputs": []). So, it should not be omitted.

Therefore, even if the original JSON cells do not have an outputs key or if the value of outputs is null, the cells in the result will always include "outputs": [].


Possible solution: We need omitnil.
See golang/go#22480

@jmnote jmnote changed the title optional & omitempty issue [known issue] for optional, omitempty or not? Jul 7, 2024
@jmnote jmnote changed the title [known issue] for optional, omitempty or not? [known issue] omitempty or not? Jul 7, 2024
@jmnote jmnote self-assigned this Jul 7, 2024
@jmnote
Copy link
Owner Author

jmnote commented Jul 7, 2024

required varies depending on the nbformat version and cell type.

// v4.0 - v4.4
// raw_cell:      "required": [      "cell_type", "metadata", "source"]
// markdown_cell: "required": [      "cell_type", "metadata", "source"]
// code_cell:     "required": [      "cell_type", "metadata", "source", "outputs", "execution_count"]

// v4.5
// raw_cell:      "required": ["id", "cell_type", "metadata", "source"]
// markdown_cell: "required": ["id", "cell_type", "metadata", "source"]
// markdown_cell: "required": ["id", "cell_type", "metadata", "source", "outputs", "execution_count"]

From v4.0 to v4.5, metadata.kernelspec.language is optional.

@jmnote jmnote mentioned this issue Jul 7, 2024
@jmnote jmnote closed this as completed Jul 7, 2024
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

No branches or pull requests

1 participant