Extracting value from nested JSON

Joined
Sep 10, 2023
Messages
1
Reaction score
0
Hi - I have a nested JSON with the following column (queue)

queue = {duration=5, name=FirstQueue}

I'm trying to extract name value above but am getting an error using this: json_extract_scalar(queue, '$.name') As Queue,

Error message: FUNCTION_NOT_FOUND: line 7:1: Unexpected parameters, Expected: json_extract_scalar(varchar(x), jsonpath), json_extract_scalar(json, jsonpath)

I'm sure my syntax is incorrect can anyone help? Thank you!
 
Joined
Nov 13, 2020
Messages
302
Reaction score
38
That is not how you write a JSON array and I found out you can't use normal methods if you only have a single object in the array and why would you? JSON is used to tie together a number of data objects for easy shipment.
Check out this page and see the code below. https://www.w3schools.com/js/js_json.asp

Code:
<!DOCTYPE HTML>
<html>
<head>
<title>Hello, HTML</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
</head>

<body>
<div id="demo"></div>
</body>
<script>
let test = '{"queue" : [{"duration":"5", "name":"FirstQueue"},{"duration":"8", "name":"LastQueue"}]}';
const obj = JSON.parse(test);
document.getElementById("demo").innerHTML = obj.queue[0].name + " " + obj.queue[0].duration;
</script>
</html>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,058
Latest member
QQXCharlot

Latest Threads

Top