How to fetch the data from json nested arrays using JSON_TABLE

How to fetch the data from json nested arrays using JSON_TABLE

book

Article ID: KB0081640

calendar_today

Updated On:

Products Versions
TIBCO Data Virtualization 7.0.x

Description

In this example, store is an array that contains arrays called book. The path expression, $.store[1].book[2], retrieves property values from these nested arrays.

SELECT
    -- {option "DISABLE_PLAN_CACHE" }
    myTitle,
    author,
    price
FROM JSON_TABLE('{
"store": [{
"book":
[{
"category_2": "reference",
"author" : "Nigel Rees",
"title": "Sayings of the Century_S1-BA1-B1",
"price": 13.95
} ,
{
"category_2": "reference",
"author" : "Nigel Rees",
"title": "Sayings of the Century_S1-BA1-B1",
"price": 12.95
}
] ,
"book": [ {
"category_2": "reference",
"author" : "Nigel Rees",
"title": "Sayings of the Century_S1-BA2-B1",
"price": 11.95
} ,
{
"category_21": "reference",
"author" : "Nigel Rees",
"title": "Sayings of the Century_S1-BA2-B2",
"price": 10.95
}
]
} ,
{
"book": [ {
"category_2": "reference",
"author" : "Nigel Rees",
"title": "Sayings of the Century_S1-BA3-B1",
"price": 9.95
} ,
{
"category_21": "reference",
"author" : "Nigel Rees",
"title": "Sayings of the Century_S1-BA3-B2",
"price": 8.95
}
]
}
]}','$.store[1].book[2]'COLUMNS(myTitle VARCHAR(100) PATH '$.title',price DOUBLE PATH '$.price',author VARCHAR(100) PATH '$.author')) JT
ORDER BY price asc

Issue/Introduction

How to fetch the data from json nested arrays using JSON_TABLE

Environment

any

Resolution


The results are fetched based on the PATH expression and then sorted by price:
 
myTitleauthorprice
Sayings of the Century_S1-BA2-B2Nigel Rees10.95
Sayings of the Century_S1-BA1-B1Nigel Rees12.95