Question: how to define schema for recursive structure?
See original GitHub issueHello,
I’ve a question about the definition of a schema for a recursive structure. Say for example I want to encode a person
which has a firstname, a lastname, and a list of children which are person
too.
How can I do that?
Basically, I would like to do:
person = {'firstname': str, 'lastname': str, Optional('children'): [person]}
Obviously, this does not work. Is there a solution?
Currently, I do something like:
person = {'firstname': str, 'lastname': str}
person[Optional('children')] = [person]
… but I find it not really readable…
Issue Analytics
- State:
- Created 7 years ago
- Reactions:2
- Comments:7
Top Results From Across the Web
JSON Schema - Recursive Schema Definition - Stack Overflow
Yes, your schema will work. The "$ref": "#" points back to the root of the schema document. However, the "type": "object" is useless:...
Read more >Recursive entity representation in JSON schema.
question is focused around statements that a JSON schema can NOT facilitate a recursive structure. This is a problem for my data
Read more >Recursive schema composition · Issue #558 · json ... - GitHub
Re-using recursive schemas is a challenge. $recurse is a specialized version of $ref with a context-dependent target; The target is the root ...
Read more >How to design a recursive menu schema?
The only option that worked was to create dedicated embedded schemas for each level. Obviously, this required relaxing the initial condition of ...
Read more >Recursive Relationships in ER diagrams - GeeksforGeeks
Here the same entity type participates more than once in a relationship type with a different role for each instance. In other words,...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Create and store the inner dict separately, following this idea:
Ah, ok, that makes sense.
For anyone finding this in the future: