Skip to main content
added 288 characters in body
Source Link
Raj
  • 31
  • 3

I have the following JSON and expecting a table out of it.

{
  "Response": [
    {
      "questionId": 1,
      "answer": [
        "5","6"
      ]
    },
    {
      "questionId": 2,
      "answer": [
        "5"
      ]
    }
  ]
}

And the expected table...

Table

I tried with the following, but didn't the exact output that i'm looking for.

SELECT QuestionId,Answer FROM OPENJSON(@responseJson, N'$.Response') r
 CROSS APPLY OPENJSON (r.value) WITH ( QuestionId   varchar(200)   '$.questionId', Answer nvarchar(max) '$.answer')

I have the following JSON and expecting a table out of it.

{
  "Response": [
    {
      "questionId": 1,
      "answer": [
        "5","6"
      ]
    },
    {
      "questionId": 2,
      "answer": [
        "5"
      ]
    }
  ]
}

And the expected table...

Table

I have the following JSON and expecting a table out of it.

{
  "Response": [
    {
      "questionId": 1,
      "answer": [
        "5","6"
      ]
    },
    {
      "questionId": 2,
      "answer": [
        "5"
      ]
    }
  ]
}

And the expected table...

Table

I tried with the following, but didn't the exact output that i'm looking for.

SELECT QuestionId,Answer FROM OPENJSON(@responseJson, N'$.Response') r
 CROSS APPLY OPENJSON (r.value) WITH ( QuestionId   varchar(200)   '$.questionId', Answer nvarchar(max) '$.answer')

I have the following JSON and expecting a table out of it.

{
  "Response": [
    {
      "questionId": 1,
      "answer": [
        "5","6"
      ]
    },
    {
      "questionId": 2,
      "answer": [
        "5"
      ]
    }
  ]
}

And the expected table is ...

TableTable

I have the following JSON and expecting a table out of it.

{
  "Response": [
    {
      "questionId": 1,
      "answer": [
        "5","6"
      ]
    },
    {
      "questionId": 2,
      "answer": [
        "5"
      ]
    }
  ]
}

And the expected table is Table

I have the following JSON and expecting a table out of it.

{
  "Response": [
    {
      "questionId": 1,
      "answer": [
        "5","6"
      ]
    },
    {
      "questionId": 2,
      "answer": [
        "5"
      ]
    }
  ]
}

And the expected table...

Table

Source Link
Raj
  • 31
  • 3

SQL Server Openjson to fetch details into a table

I have the following JSON and expecting a table out of it.

{
  "Response": [
    {
      "questionId": 1,
      "answer": [
        "5","6"
      ]
    },
    {
      "questionId": 2,
      "answer": [
        "5"
      ]
    }
  ]
}

And the expected table is Table