JSON and SQL Tutorial - Convert a table to JSON and JSON to table

  Рет қаралды 124,771

James Oliver

James Oliver

Күн бұрын

In this video I will show you how to convert JSON to a table using OPENJSON and from a table to JSON using FOR JSON PATH with t-sql. I will also cover querying specific JSON objects using JSON_VALUE as well as validating JSON using ISJSON.

Пікірлер: 81
@Ferruccio_Guicciardi
@Ferruccio_Guicciardi 8 ай бұрын
Thanks for sharing the most flexible way to define the JSON tree from the dataset source !
@mahsapourshahmari8458
@mahsapourshahmari8458 2 жыл бұрын
I really like the way you say OKAY :) it makes it sound too easy to follow, like you get it? it is that simple :)
@jaxamokoto2783
@jaxamokoto2783 11 ай бұрын
Exactly what I needed! Thank you!!
@javaguitarist
@javaguitarist Жыл бұрын
This helped me enormously - thank you!
@cubicle_monkey
@cubicle_monkey 2 жыл бұрын
I FINALLY got this working! Thanks for the walk through. If you had to iterate this process through multiple files, what do you think would work best?
@MrsHelepolis
@MrsHelepolis 4 жыл бұрын
Hello james ,i'm using mongo atlas sample database to train myself. i have an array in json format "cast": [ "Charles Kayser", "John Ott" ] how do i transfer this array to table?
@dannyanicamamasgo6482
@dannyanicamamasgo6482 3 жыл бұрын
Thx Jame! one question, how to process when there is character special column "año" json? Like n'$."Dueño Data"
@KukuFamily
@KukuFamily 2 жыл бұрын
Hi Oliver , we get json as a single row data, is it possible to have separate json row for each record?
@oussamaoussama6364
@oussamaoussama6364 4 жыл бұрын
Pardon my out of context question: can you please upload the back propagation video for the neural networks series? Great explanation by the way.
@utkarshverma1832
@utkarshverma1832 3 жыл бұрын
Hi James, Just on the same Context can we create an JSON output file from the MSSQL with suffix of DATE time. Can we do this? Can we insert the data into a table of SQL so that i can import it? How can i read a JSON file which has ABCD_XX_12345_
@mehmetkaya4330
@mehmetkaya4330 11 ай бұрын
Super!!! Thank you so much for this great tutorial
@justdrawit3038
@justdrawit3038 2 жыл бұрын
Very clear! 👍
@andynelson2340
@andynelson2340 3 жыл бұрын
Awesome, thanks!
@MrYeduguri
@MrYeduguri 4 жыл бұрын
Kindly explain various grid formatting options and document formatting options as well James. Thanks in advance!
@sonaligund
@sonaligund 3 жыл бұрын
could you please guide how to create json from table data in oracle 11g. It would be helpful. Thanks.
@barryreeves6916
@barryreeves6916 3 жыл бұрын
Very Helpful. Thanks
@ppp.1334
@ppp.1334 3 жыл бұрын
do we always have to paste whole json into the code?
@paapaasare
@paapaasare 3 жыл бұрын
How would this work on data from a json API url?
@hadireg
@hadireg 4 жыл бұрын
👍👍 Thanks!
@monikamalladi5603
@monikamalladi5603 3 жыл бұрын
In JSON to table section using OPENJSON where can we assign the table name ?
@voltairend
@voltairend 3 жыл бұрын
Thanks James
@dexter9459
@dexter9459 3 жыл бұрын
hey chief got the following error with this "Msg 319, Level 15, State 1, Line 27 Incorrect syntax near the keyword 'with'. If this statement is a common table expression, an xmlnamespaces clause or a change tracking context clause, the previous statement must be terminated with a semicolon." with your query directly from your google docs
@programminglearner4652
@programminglearner4652 2 жыл бұрын
Can we convert JSON (data received from api) to MySQL table for cloning api data
@Imaginativeone_DF
@Imaginativeone_DF 2 жыл бұрын
Will these functions work with SQLite?
@abp4110
@abp4110 2 жыл бұрын
How do I add a fetched JSON api and get value of the returned value ?
@workstephens3135
@workstephens3135 4 жыл бұрын
Anyway you can provide as downloads the original .txt and .sql files you have entered above? I try to type exactly as you have it but still get errors. Msg 102, Level 15, State 1, Line 1 - Incorrect syntax near '{'.Msg 103, Level 15, State 4, Line 2, The identifier that starts with '
@JamesOliver
@JamesOliver 4 жыл бұрын
Here you go: drive.google.com/file/d/1LIeumrtwskcrAzSU194Mt3HyLjLCiYE_/view?usp=sharing
@theilluminatimember8896
@theilluminatimember8896 2 жыл бұрын
Is is possible to cast values like this from a json *column* as well? I'm struggling with a Laravel project where I need to order rows by a value stored in a json column. The problem is the default Laravel query builder orders it like a string where as I need it ordered numerically. If it's possible to cast the values into a numeric datatype it would sort properly.
@javaguitarist
@javaguitarist Жыл бұрын
I had the same situation where the Qty number was a string in the json. If you use the WITH like he describes, you can cast it by just defining the type right there. WITH ( Qty DECIMAL(18,3) '$.qtyOrd' )
@theilluminatimember8896
@theilluminatimember8896 Жыл бұрын
​@@javaguitarist I ended up solving it like this: ```php public function scopeIncludeJsonProp(Builder $query, $attribute, $name = null) { $attribute = str_replace('->', '.', $attribute); $path = explode('.', $attribute); if (in_array($path[0], $this->jsonColumns)) { $jsonSelector = '$.' . implode(".", array_slice($path, 1)); $cast = $this->jsonCasts[$attribute] ?? $this->defaultJsonCast; return $query->selectRaw("cast(json_value(`$path[0]`, '$jsonSelector') as $cast) as `". (!empty($name) ? $name : $attribute) . "`"); } return $query; } ``` I've put it inside a global scope method so I can use it everywhere
@theilluminatimember8896
@theilluminatimember8896 Жыл бұрын
I also added model attributes allow me to cast each the json value automatically in case of date, char or decimal This all allowed me to include it sort and filter using sql which is SECONDS faster (from 2 seconds avg to 0.5 seconds avg)
@sachin3941
@sachin3941 4 жыл бұрын
How do i convert a whole column having many jsons to a table format?
@JamesOliver
@JamesOliver 3 жыл бұрын
I'm planning a follow-up video showing more complex examples.
@n.boukari6323
@n.boukari6323 Жыл бұрын
Thank u kann as solution for the big data manipulation
@hiphopheaven
@hiphopheaven 2 жыл бұрын
Does it works with postgres?
@hasanmougharbel8030
@hasanmougharbel8030 Жыл бұрын
God bless your great efforts in this channel. I have a simple question to ask as a newbie sql learner. Could i manage to channel or extract all sql data generated from an accounting program (based on sql) to our new sql server. The reason that we are bounded with the graphical interface of this accounting software as we cant come up with any solutions regarding analytics and automation, unless we can tailor and rearrange this sql database based to our specific needs. Thanks for helping me.
@javaguitarist
@javaguitarist Жыл бұрын
That is a very large question and many possible answers that depend upon many factors in your environment, all of which are too involved to put into KZbin comments. I suggest you look at SSIS if you need to transform the data after copying it. But the simplest way to start is: In SSMS right click the source database. Open Tasks, then either Export Data or Copy Database. Do this on a test system! Good luck.
@giaptiennbros
@giaptiennbros 3 жыл бұрын
Hi James, does it work if I work with Oracle ?
@JamesOliver
@JamesOliver 3 жыл бұрын
Joe G Unfortunately I have zero experience with Oracle believe it or not. It is a good question.
@MrYeduguri
@MrYeduguri 4 жыл бұрын
Hi James, appreciate your efforts. Please make a video on "conditional metric embedding methods in microstrategy.
@JamesOliver
@JamesOliver 4 жыл бұрын
Thank you for the suggestion. I will add to my list of ideas for potential future videos.
@MrYeduguri
@MrYeduguri 4 жыл бұрын
@@JamesOliver.. thanks James!!
@renz82
@renz82 Жыл бұрын
How do you do this for oracle database?
@gauravdutta5486
@gauravdutta5486 2 жыл бұрын
Hello Sir ., which db is this Do we have to do the same thing in postgres
@JamesOliver
@JamesOliver 2 жыл бұрын
SQL Server Express
@codeflu
@codeflu 11 ай бұрын
I have created Web tool to generate tables from complex JSON effortlessly and run SQL queries for powerful data analysis
@karlethapaxton7281
@karlethapaxton7281 Жыл бұрын
cool
@Kraver97
@Kraver97 3 жыл бұрын
Hi James, I am getting error: "Incorrect syntax near the keyword 'with'. If this statement is a common table expression, an xmlnamespaces clause or a change tracking context clause, the previous statement must be terminated with a semicolon.". I read to put ";" before "WITH" but then I get: "Incorrect syntax near '('.". Please help me. :) (Error occur even with yours .txt drive.google.com/file/d/1LIeumrtwskcrAzSU194Mt3HyLjLCiYE_/view?usp=sharing).
@Kraver97
@Kraver97 3 жыл бұрын
I find out that OPENJSON() function requires at least 130lv of Compatibility where my level is only 110 (I cannot change that). So I change my question to: Is there any other way to do what you did on video?
@pratikpatra67
@pratikpatra67 3 жыл бұрын
Hello James, Why you've used N while setting the value in JSON
@JamesOliver
@JamesOliver 3 жыл бұрын
Just means Unicode. Not really anything major to focus on. ;)
@pratikpatra67
@pratikpatra67 3 жыл бұрын
@@JamesOliver Thanks 🙂
@gkri8390
@gkri8390 3 жыл бұрын
How to enrich json from column from another table
@v300
@v300 2 жыл бұрын
What SQL is this Oracle or DB/2?
@JamesOliver
@JamesOliver 2 жыл бұрын
T-sql ie sql server
@jobsjobs9987
@jobsjobs9987 3 жыл бұрын
Can you do this in SQL SERVER 2014? Using BUILT IN JSON components?
@JamesOliver
@JamesOliver 3 жыл бұрын
Pretty sure it started with 2012
@tchpowdog
@tchpowdog 2 жыл бұрын
I think it's 2016 and later docs.microsoft.com/en-us/sql/relational-databases/json/json-data-sql-server?view=sql-server-ver15
@taricov4662
@taricov4662 3 жыл бұрын
Can anybody explains to me why the Dollar sign $ is used? I am new to SQL
@DefriaManda
@DefriaManda 2 жыл бұрын
The "$." denotes the root node, in the JSON object. The string value directly after "$." is the ROOT node.
@gameisrigged6942
@gameisrigged6942 3 жыл бұрын
Ok
@tingholm
@tingholm 3 жыл бұрын
counted 57 :) reminds me of Robyns from HIMYM drinking game. "But-ehmm"
@sradhawebcreations
@sradhawebcreations 3 жыл бұрын
How to send SQL server data to json file
@JamesOliver
@JamesOliver 3 жыл бұрын
Do you mean export to a file?
@rossocorsa6577
@rossocorsa6577 3 жыл бұрын
Okay?
@gameisrigged6942
@gameisrigged6942 3 жыл бұрын
Ok
@tingholm
@tingholm 3 жыл бұрын
counted 57 :) reminds me of Robyns from HIMYM drinking game. "But-ehmm"
@peterkhumalo9837
@peterkhumalo9837 3 жыл бұрын
Why am i getting NULL values..Please help
@javaguitarist
@javaguitarist Жыл бұрын
Please learn how to ask questions properly. Put yourself in the position of the reader and have respect for the free time and effort you are asking for. You give absolutely no information about your query at all. We are looking at a blank slate, and you ask why am I getting null values. How would you expect anyone to help you? In a lot of technical forums you could be banned for wasting people's time just for asking a question that way. I'm not trying to be mean but am trying to help you save time, learn faster, and get help and not have your unanswered questions ticking off people who would otherwise be happy to help you.
@FredyArg
@FredyArg 4 жыл бұрын
also, can you do a sample json creation query where there are over 50,000 records? its kind of cute with four or how ever many you are using.
@JamesOliver
@JamesOliver 4 жыл бұрын
Fred E yea this video was just about the concepts not necessarily specific implementations but will take the feedback into consideration.
@FredyArg
@FredyArg 4 жыл бұрын
James Oliver ugh I am sorry, I didn’t mean for that to come out like that, yes thank you for making the video.
@JamesOliver
@JamesOliver 4 жыл бұрын
Fred E It’s all good. I appreciate you watching! :)
@tchpowdog
@tchpowdog 2 жыл бұрын
If you're concerned about performance, I've tested FOR JSON with millions of records and the performance difference is negligible. When going from table to json, all FOR JSON does is convert the query result to a serialized json format (a string) - this is not a resource heavy or time consuming task from what I've seen. Your queries still need to be properly structured and optimized, like normal. Test it - write a query that returns 50,000 records. Add subselects, joins, whatever you want. Run it. Then slap "for json path" on the end of it and run it again - this generally works with straigtforward queries. You'll have to alias your subselects.
@mohammedameen6583
@mohammedameen6583 3 жыл бұрын
Which ide is this
@javaguitarist
@javaguitarist Жыл бұрын
SQL Server Management Studio. It is a free download from Microsoft.
@raunelperez9421
@raunelperez9421 2 жыл бұрын
I just listen "ok ok ok"
@KimboH55
@KimboH55 3 жыл бұрын
ok ok okay
@hyungtaecf
@hyungtaecf 2 жыл бұрын
This json looks bad. It doesn’t actually needs the “customers” and “customer” keys. It could be simplified as just a json array with key-value pairs of id and body.
@Pollux70
@Pollux70 Жыл бұрын
STOP saying ok after every sentence you're not a parrot, ok.
Full outer joins don't get enough love
6:06
James Oliver
Рет қаралды 3,3 М.
Convert rows from a SQL Query or Table to JSON format
10:18
SQL with Manoj
Рет қаралды 22 М.
New Gadgets! Bycycle 4.0 🚲 #shorts
00:14
BongBee Family
Рет қаралды 12 МЛН
Тяжелые будни жены
00:46
К-Media
Рет қаралды 5 МЛН
Как быстро замутить ЭлектроСамокат
00:59
ЖЕЛЕЗНЫЙ КОРОЛЬ
Рет қаралды 11 МЛН
Learning MySQL - JSON in MySQL
19:12
Steve Griffith - Prof3ssorSt3v3
Рет қаралды 64 М.
Learn JSON in 10 Minutes
12:00
Web Dev Simplified
Рет қаралды 3,1 МЛН
Deep dive: Using JSON with SQL Server
43:08
SQL with Manoj
Рет қаралды 20 М.
You don't need NoSQL (use MySQL)
31:26
PlanetScale
Рет қаралды 73 М.
SQL CTEs (Common Table Expressions) - Why and How to Use Them
7:56
Database Star
Рет қаралды 24 М.
Advanced SQL Tutorial
11:25
James Oliver
Рет қаралды 101 М.
Dynamically Pivot Data in SQL Server
13:50
Anthony Smoak
Рет қаралды 81 М.
New Gadgets! Bycycle 4.0 🚲 #shorts
00:14
BongBee Family
Рет қаралды 12 МЛН