Forum Discussion
Fetching JSON object from Cosmos DB in Azure Synapse Studio fails
Hi everyone!
- fetching this object as:
- VARCHAR(MAX)
- NVARCHAR(MAX)
- identifying full path in WITH clause:
- failing_complex_object VARCHAR(MAX) '$.failing_complex_object'
- trying to decompose it in SELECT clause:
- ,JSON_QUERY([target_table].[failing_complex_object])
- ,JSON_VALUE(failing_complex_object, '$.failing_complex_object')
It always returns NULL.
- Complex objects without issue are bigger size and one of them is JSON object,
the other one is JSON array. - Complex object with issue is a valid JSON object.
Data examples are below.
P.S.
Due to NDA cannot share with you the actual DB data but I assure you that SCHEME is absolutely the same.
P.S. P.S.
Sorry for JSON and SQL examples. Couldn't load all the examples using "Insert code sample" tool. It didn't work.
fetch example
1 Reply
Would suspect that the reason your failing_complex_object always returns NULL is that Synapse OPENROWSET with Cosmos DB doesn’t automatically flatten nested JSON objects into string columns. Arrays and simple objects serialize fine, but nested objects with multiple child properties (like your data_01 and data_02) often fail unless you explicitly cast them as NVARCHAR(MAX) and then use JSON_QUERY without a path. In other words, the column definition in your WITH clause is discarding the nested object because Synapse expects a scalar value, not a structured JSON object.