Find JSON Schema in SQL Server

2019-08-01 16:55发布

问题:

I have JSON in a field, but I need to check it's schema before I process it. I need to know if anything has been added or removed from the schema.

Is there a way to extract the JSON schema from a JSON string so I can compare it to a known schema?

An online example is http://jsonschema.net/, but I want to do the same thing in TSQL

回答1:

SQL Server don't support any json schema binding.

If your JSON is simple or flat, you can use

SELECT [key] FROM OPENJSON(@json)

to find all keys on the first level and compare them with some expected key set.