Skip to content

Minimal example for nested optional JSON fields #52

Description

@matu3ba

I am curious, if (de)serializing from and to minimal nested optional JSON fields <-> struct describing the JSON with boolean fields to existence of the optional fields is a supported use case.

If yes, can you give me some pointers on the big picture of how the code would look?
Ideally with a minimal usable example, if it is not too much effort.

Thanks for your effort.

UPDATE: Code for the use case
Assume a JSON schema

{
  "required_field":"data1","optional_field":{"req_field_of_optional":"data2","nested_opt_field":"data3"}
}

which fills

struct json_repr {
  typeof(data1) required_field;
  bool optional_field_isUsed;
  typeof(data2) req_field_of_optional;
  bool nested_opt_field_isUsed;
  typeof(data3) nested_opt_field;
};

Another conforming JSON schema would be

{
  "required_field":"data1"
}

and another one

{
  "required_field":"data1","optional_field":{"req_field_of_optional":"data2"}
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions