Reputation: 9
Answers to a questionnaire are stored in json in a column in this table. I need to pull out the answer to a specific question stored within this column, but am struggling to do so.
I want to get the postValue '123456789' as 'Incorporation Number'
I am not sure how to get the specific child element value - any help much appreciated.
select json_extract(table.json_column, '$.user_data.element.postValue') as 'json'
from table
where table.id = 123
the json looks something like the below:
{
"risk_data":[
],
"user_data":[
"elements":[
{
"postName":"postNameInput",
"postValue":"TEST COMPANY"
}
],
"language":"english",
"elementId":"100",
"sectionId":"9",
"weightage":null,
"isHyperLink":0,
"elementIndex":0,
"elementTitle":{
"english":"Company's Full Legal Name"
},
"hyperLinkUrl":null,
"isWorkFlowNa":0,
"sectionIndex":0,
"sectionTitle":{
"english":"Basic Company Information"
},
"hyperLinkText":null,
"isMultiSelect":0,
"selectedChart":null,
"dataAttributes":null,
"elementTitleAbb":{
"english":"Company's Full Legal Name"
},
"isHiddenElement":0,
"isHiddenSection":0,
"elementInputType":"input",
"elementFooterText":null,
"elementHeaderText":null,
"elementDescription":null,
"hyperLinkTextAfter":null,
"question_abb_table":null,
"hyperLinkTextBefore":null,
"enableSelfReportingForManageThirdParty":0,
"enableSelfReportingForThirdPartyProfile":0
}, {
"elements":[
{
"postName":"postNameInput",
"postValue":"123456789"
}
],
"language":"english",
"elementId":"101",
"sectionId":"10",
"weightage":null,
"isHyperLink":0,
"elementIndex":4,
"elementTitle":{
"english":"Incorporation Number"
},
"hyperLinkUrl":null,
"isWorkFlowNa":0,
"sectionIndex":3,
"sectionTitle":{
"english":"Organisational Structure"
},
"hyperLinkText":null,
"isMultiSelect":0,
"selectedChart":null,
"dataAttributes":null,
"elementTitleAbb":{
"english":"Incorporation Number"
},
"isHiddenElement":0,
"isHiddenSection":0,
"elementInputType":"input",
"elementFooterText":null,
"elementHeaderText":null,
"elementDescription":null,
"hyperLinkTextAfter":null,
"question_abb_table":null,
"hyperLinkTextBefore":null,
"enableSelfReportingForManageThirdParty":0,
"enableSelfReportingForThirdPartyProfile":0
},
Upvotes: 0
Views: 32