Handling Complex JSON Schemas in Python
Handling complex JSON Schemas in Python - Grammofy - Medium
In a previous post we looked at how to test your Python API app with JSON Schema. In case you have to deal with complex and nested JSON data, schema definitions can get long and confusing. However, there are ways to clean up and reuse your schemas by using references. Let’s see what they are and how you can leverage them in your testing setup.Internal ReferencesLet’s take an example endpoint GET /recordings/:id which returns a JSON response for a recording of a classical music piece:We have a work object with a composer and there is a list of recording artists, which include the musicians and technical personnel. All three of them–the composer, the pianist, and the engineer/producer–share the same data structure of an artist.Using the above JSON response, the corresponding JSON Schema would look like this:We repeated the schema for artists twice. There is a cleaner way of defining this structure…