You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, I am trying to extract Key and Values along with row id for each key and value. Here is the json example. {"rowid": "1", "freeresponses": { "fr1": "1.1", "fr2": "1.1", "fr3": "1.3", "fr4": "1.4", "fr5": "1.4", "fr6": "1.4" }}
I tried this with t-SQL and i get desired result. SELECT convert (int, JSON_VALUE(jsontext,'$.rowid' )) as rowid, c.[key], c.[value] FROM dbo.tmp# cross apply openjson(json_query(jsontext,'$.freeresponses') ) as c;
TSQL results
1 fr1 1.1
1 fr2 1.1
1 fr3 1.3
1 fr4 1.4
1 fr5 1.4
I tired the following USQL
`//Read Json
@freeresponse1 =
EXTRACT rowid string,
freeresponses string
FROM @inputfile
USING new MultiLevelJsonExtractor("*", false,
"rowid",
"freeresponses");
// Convert the JSON column to SQL MAP to multiple rows
@freeresponsevalues =
SELECT rowid,
JsonFunctions.JsonTuple(freeresponses).Values AS frvalues
FROM @freeresponse1;
//Explode Tuple
@freeresponsevaluesx =
SELECT rowid
,c.value AS frvalues
FROM @freeresponsevalues
CROSS APPLY
EXPLODE(frvalues) AS c(value);`
I am not able to get the keys as I know where that should be mentioned in USQL. I tired c(key,value) on the last line but that errors out.
Any help will be appreciated.
The text was updated successfully, but these errors were encountered:
Hi, I am trying to extract Key and Values along with row id for each key and value. Here is the json example.
{"rowid": "1", "freeresponses": { "fr1": "1.1", "fr2": "1.1", "fr3": "1.3", "fr4": "1.4", "fr5": "1.4", "fr6": "1.4" }}
I tried this with t-SQL and i get desired result.
SELECT convert (int, JSON_VALUE(jsontext,'$.rowid' )) as rowid, c.[key], c.[value] FROM dbo.tmp# cross apply openjson(json_query(jsontext,'$.freeresponses') ) as c;
TSQL results
1 fr1 1.1
1 fr2 1.1
1 fr3 1.3
1 fr4 1.4
1 fr5 1.4
I tired the following USQL
`//Read Json
@freeresponse1 =
EXTRACT rowid string,
freeresponses string
FROM @inputfile
USING new MultiLevelJsonExtractor("*", false,
"rowid",
"freeresponses");
// Convert the JSON column to SQL MAP to multiple rows
@freeresponsevalues =
SELECT rowid,
JsonFunctions.JsonTuple(freeresponses).Values AS frvalues
FROM @freeresponse1;
//Explode Tuple
@freeresponsevaluesx =
SELECT rowid
,c.value AS frvalues
FROM @freeresponsevalues
CROSS APPLY
EXPLODE(frvalues) AS c(value);`
I am not able to get the keys as I know where that should be mentioned in USQL. I tired c(key,value) on the last line but that errors out.
Any help will be appreciated.
The text was updated successfully, but these errors were encountered: