This questions is about generating Source Code, i.e. not something dynamic at runtime but an actual python file that can be manually edited and extended.
Assuming I have a JSON string which deserialises to a non trival group of nested dictionaries, e.g.
{
'person': {
'name': {
'first_name' : 'foo',
'last_name' : 'bar'
}
}
}
Is there a way to generate python classes, as source code , such that I have a series of classes that nest together and potentially even a constructor at the top level class which can take the same JSON string and populate itself and associated classes?
I've looked at similar questions and some mention warlock, but this seems to generate the code dynamically and also includes type validators and requires a JSON schema rather than an actual example.
I'm looking again for something that will provide class files / source. I started doing this manually but I feel like there might be some pythonic magic out there which will save me time.
http://www.jsonschema2pojo.org/ Is close to what I'm looking for, but the wrong language (It generates Java). I'm looking at taking the output of this service and running https://github.com/natural/java2python over it to create the python I want, but this is getting convoluted and also doesn't include any constructors or class methods that can take the original populated json as an argument.
Does what I'm looking for exist out there?