'Jsonstring to sql result table with OpenJson
I like to use some elements (field and value's indicated by **<field or value>**) of the ***content*** part of my json string in SQL.
The difficult part is the 2 data components.
How can I do this? Can anyone help with the SQL code ?
this is my select statement and @json:
SELECT
tableA.*
-- and all bold fields and values from the content
FROM OpenJson(@json)
with (
myform varchar(100) '$.name.value',
content nvarchar(max) as json
) as Table_A
{
"name": {
"_type": "DV_TEXT",
"value": "**some measureform**",
"mappings": []
},
"***content***": [
{
"data": {
"name": {
"_type": "DV_TEXT",
"value": ""
},
"events": [
{
"data": {
"name": {
"_type": "DV_TEXT",
"value": "",
"mappings": []
},
"_type": "ITEM_TREE",
"items": [
{
"name": {
"_type": "DV_TEXT",
"value": "**Used Area**"
},
"_type": "ELEMENT",
"value": {
"_type": "DV_CODED_TEXT",
"value": "**Movement**",
"defining_code": {
"code_string": "at0.4",
"terminology_id": {
"value": "ac0.2"
}
}
},
"archetype_node_id": "id0.4"
},
{
"name": {
"_type": "DV_TEXT",
"value": "**Starting point**"
},
"_type": "ELEMENT",
"value": {
"_type": "DV_CODED_TEXT",
"value": "**Unknown**",
"defining_code": {
"code_string": "at0.3",
"terminology_id": {
"value": "ac0.1"
}
}
},
"archetype_node_id": "id0.2"
},
{
"name": {
"_type": "DV_TEXT",
"value": "**Type conversion**"
},
"_type": "ELEMENT",
"links": [],
"value": {
"_type": "DV_CODED_TEXT",
"value": "**Ordering**",
"mappings": [],
"defining_code": {
"code_string": "at0.8",
"terminology_id": {
"value": "ac0.3"
}
}
},
"archetype_node_id": "id5.2"
},
{
"name": {
"_type": "DV_TEXT",
"value": "**Duration**"
},
"_type": "ELEMENT",
"value": {
"_type": "DV_DURATION",
"value": "**PT5M**"
},
"archetype_node_id": "id7"
},
{
"name": {
"_type": "DV_TEXT",
"value": "**Health**"
},
"_type": "ELEMENT",
"links": [],
"value": {
"_type": "DV_CODED_TEXT",
"value": "**Good**",
"defining_code": {
"code_string": "at6",
"terminology_id": {
"value": "ac3"
}
}
},
"archetype_node_id": "id9"
},
{
"name": {
"_type": "DV_TEXT",
"value": "**Inserted**"
},
"_type": "ELEMENT",
"value": {
"_type": "DV_CODED_TEXT",
"value": "**No**",
"defining_code": {
"code_string": "at4",
"terminology_id": {
"value": "ac2"
}
}
},
"archetype_node_id": "id11"
},
{
"name": {
"_type": "DV_TEXT",
"value": "**Description**"
},
"_type": "ELEMENT",
"value": {
"_type": "DV_TEXT",
"value": "**Some text**"
},
"archetype_node_id": "id13"
}
],
"links": [],
"archetype_node_id": "id4"
},
"name": {
"_type": "DV_TEXT",
"value": "**Interuption time**"
},
"time": {
"value": "**2022-02-03T17:11:05+01:00**"
},
"_type": "POINT_EVENT",
"archetype_node_id": "id3"
}
],
"origin": {
"value": "**2022-02-03T17:11:05+01:00**"
},
"archetype_node_id": "id2"
},
"name": {
"_type": "DV_TEXT",
"value": "**Some classification**"
},
"_type": "OBSERVATION",
"archetype_node_id": "id0.0.100.1"
},
{
"data": {
"name": {
"_type": "DV_TEXT",
"value": ""
},
"_type": "ITEM_TREE",
"items": [
{
"name": {
"_type": "DV_TEXT",
"value": "**Remarks**"
},
"_type": "ELEMENT",
"value": {
"_type": "DV_TEXT",
"value": "**Some text here** "
},
"archetype_node_id": "id3.1"
}
],
"archetype_node_id": "id2"
},
"name": {
"_type": "DV_TEXT",
"value": "**Remark**"
},
"_type": "EVALUATION",
"archetype_node_id": "id0.0.101"
}
]
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
