Look into Python libraries for translating JSON to Python data structures
Look into work that Ali did last summer and see what he was using initially. Ask Andrei for recommendations.
A combination these should work pretty well at loading the JSON.
-
@dataclass(frozen=true). - https://github.com/konradhalas/dacite
It can load JSON directly into an immutable object. If we could extract the fpp-to-json JSON schema we could generate the corresponding dataclasses in python. Optimally this would be automated so that FPP changes don't break the Python package.
Thanks @Kronos3! I noticed that in some of our other tools, Pydantic is used. It looks like Pydantic is more for reading and validating JSON content - are you familiar that library or see any use case for it here?
Ah yes that's probably better, bigger dependency but it looks like it already has the json schema -> python class: https://docs.pydantic.dev/latest/integrations/datamodel_code_generator/#example
Pydantic is already part of our requirements https://github.com/nasa/fprime/blob/14bac5f350fef9add6c58592c690ebdabfbc83c7/requirements.txt#L59
It would be nice to see it used more! I haven't really looked into it myself... but it seemed promising
Looked into auto-generating the Python data structures via pydandtic's code generator but the output was not something we can work with. Also tried generating a JSON schema for the fpp-to-json output before generating the Python data structures and that also did not work well. Decided to go the route of converting FPP scala AST to Python by hand. Have notes in the wiki on the way we represent FPP AST in Python here.