def _sort_schema(schema):
if isinstance(schema, dict):<EOL><INDENT>for k, v in sorted(schema.items()):<EOL><INDENT>if isinstance(v, dict):<EOL><INDENT>yield k, OrderedDict(_sort_schema(v))<EOL><DEDENT>elif isinstance(v, list):<EOL><INDENT>yield k, list(_sort_schema(v))<EOL><DEDENT>else:<EOL><INDENT>yield k, v<EOL><DEDENT><DEDENT><DEDENT>elif isinstance(schema, list):<EOL><INDENT>for v in schema:<EOL><INDENT>if isinstance(v, dict):<EOL><INDENT>yield OrderedDict(_sort_schema(v))<EOL><DEDENT>elif isinstance(v, list):<EOL><INDENT>yield list(_sort_schema(v))<EOL><DEDENT>else:<EOL><INDENT>yield v<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>yield d<EOL><DEDENT>
Recursively sorts a JSON schema by dict key.