Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

3
  • If you do it without WITH at all then you get three columns: key value and type, each row is one property of the object (or one object in an array). This may still be useful for you in order to dynamically retrieve specific keys. If you give more detail on your use case there may be something to be done. Do you need the actual columns coming out of your function to be dynamic, or is it just that you want to get the data from the JSON dynamically? Commented Feb 13, 2022 at 22:48
  • What I'm looking for in T-SQL is an equivalent to Oracle's "JSON_DATAGUIDE" to get the schema. specifically the "o:path" : "$.PO_ID", The JSON I'm working with is very simple, no nesting, no crazy formats just rows and columns. The twist is each client will have different columns in their output. One may have name, surname. Another may have street and restaurant. So what I'm needing is to be able to pull out the JSON record keys (aka column names). Christ, I'm lost with this.
    – TPV
    Commented Feb 13, 2022 at 23:07
  • 1
    OPENJSON will only break open one level. You can get a full graph by using a recursive CTE to recursively open each array or object, for example dbfiddle.uk/…. Is this what you wanted? It's very unclear what your actual wanted results are. Please show what you are actually trying to achieve Commented Feb 13, 2022 at 23:19