{"id":204,"title":"SQL Notlar\u0131:   JSON Veri T\u00fcr\u00fc ve \u0130\u015flemleri","content":"<p>MySQL 5.7.8 ve sonraki s\u00fcr\u00fcmler, JSON (JavaScript Object Notation) veri t\u00fcr\u00fcn\u00fc destekler. Bu \u00f6zellik, JSON format\u0131ndaki verileri veritaban\u0131nda saklamay\u0131 ve bu veriler \u00fczerinde \u00e7e\u015fitli i\u015flemler yapmay\u0131 kolayla\u015ft\u0131r\u0131r. Bu yaz\u0131da, MySQL'de JSON veri t\u00fcr\u00fcn\u00fcn nas\u0131l kullan\u0131laca\u011f\u0131n\u0131, JSON verilerinin nas\u0131l eklenece\u011fini, g\u00fcncellenece\u011fini ve nas\u0131l \u00e7\u0131kar\u0131laca\u011f\u0131n\u0131 ele alaca\u011f\u0131z.<\/p><p>#### 1. JSON Veri T\u00fcr\u00fc ile Tablo Olu\u015fturma<\/p><p>JSON veri t\u00fcr\u00fc, bir tabloda JSON format\u0131nda veri saklamak i\u00e7in kullan\u0131l\u0131r. A\u015fa\u011f\u0131daki \u00f6rnekte, birincil anahtar ve JSON s\u00fctunu i\u00e7eren bir tablo olu\u015fturulmu\u015ftur:<\/p><p>```sql<br>CREATE TABLE table_name (<br>&nbsp; &nbsp;id INT NOT NULL AUTO_INCREMENT,<br>&nbsp; &nbsp;json_col JSON,<br>&nbsp; &nbsp;PRIMARY KEY(id)<br>);<br>```<\/p><p>#### 2. JSON Verisi Ekleme<\/p><p>JSON verisi, bir tabloya eklenirken JSON format\u0131nda bir dize olarak belirtilir. JSON anahtarlar\u0131 \u00e7ift t\u0131rnak i\u00e7inde olmal\u0131d\u0131r.<\/p><p>##### \u00d6rnek: Basit JSON Verisi Ekleme<\/p><p>```sql<br>INSERT INTO table_name (json_col)<br>VALUES ('{\"city\": \"Galle\", \"Description\": \"Best damn city in the world\"}');<br>```<\/p><p>Bu \u00f6rnekte, `json_col` s\u00fctununa bir JSON nesnesi eklenmi\u015ftir.<\/p><p>#### 3. JSON Verisini G\u00fcncelleme<\/p><p>JSON verisini g\u00fcncellemek i\u00e7in `JSON_ARRAY_APPEND`, `JSON_SET` gibi JSON fonksiyonlar\u0131 kullan\u0131l\u0131r.<\/p><p>##### \u00d6rnek: JSON Dizisine Eleman Ekleme<\/p><p>A\u015fa\u011f\u0131daki \u00f6rnekte, `variations` dizisine yeni bir eleman eklenmi\u015ftir:<\/p><p>```sql<br>UPDATE myjson<br>SET dict = JSON_ARRAY_APPEND(dict, '$.variations', 'scheveningen')<br>WHERE id = 2;<br>```<\/p><p>**Sonu\u00e7:**<br>```<br>+---+---+<br>| id | dict &nbsp; &nbsp;|<br>+---+---+<br>| 2 | {\"opening\": \"Sicilian\", \"variations\": } |<br>+---+---+<br>```<\/p><p>#### 4. JSON Verisini CAST ile D\u00f6n\u00fc\u015ft\u00fcrme<\/p><p>JSON format\u0131ndaki bir dizeyi JSON veri t\u00fcr\u00fcne d\u00f6n\u00fc\u015ft\u00fcrmek i\u00e7in `CAST` fonksiyonu kullan\u0131l\u0131r.<\/p><p>##### \u00d6rnek: JSON Dizesini JSON T\u00fcr\u00fcne D\u00f6n\u00fc\u015ft\u00fcrme<\/p><p>```sql<br>SELECT CAST('' AS JSON);<br>SELECT CAST('{\"opening\":\"Sicilian\",\"variations\":}' AS JSON);<br>```<\/p><p>#### 5. JSON Nesnesi ve Dizisi Olu\u015fturma<\/p><p>`JSON_OBJECT` ve `JSON_ARRAY` fonksiyonlar\u0131 ile JSON nesneleri ve dizileri olu\u015fturulabilir.<\/p><p>##### \u00d6rnek: JSON Nesnesi ve Dizisi Olu\u015fturma<\/p><p>```sql<br>SELECT JSON_OBJECT('key1', col1, 'key2', col2, 'key3', 'col3') AS myobj;<br>SELECT JSON_ARRAY(col1, col2, 'col3') AS myarray;<br>```<\/p><p>Kar\u0131\u015f\u0131k JSON verisi olu\u015fturmak i\u00e7in:<\/p><p>```sql<br>SELECT JSON_OBJECT(\"opening\", \"Sicilian\", \"variations\", JSON_ARRAY(\"pelikan\", \"dragon\", \"najdorf\")) AS mymixed;<br>```<\/p><p>#### 6. JSON Verisinden De\u011fer \u00c7\u0131karma<\/p><p>JSON verisinden belirli de\u011ferleri \u00e7\u0131karmak i\u00e7in `JSON_EXTRACT` fonksiyonu veya `-&gt;`, `-&gt;&gt;` operat\u00f6rleri kullan\u0131l\u0131r.<\/p><p>##### \u00d6rnek: JSON Dizisinden De\u011fer \u00c7\u0131karma<\/p><p>```sql<br>SET @myjson = CAST('' AS JSON);<\/p><p>SELECT<br>&nbsp; &nbsp;JSON_EXTRACT(@myjson, '$'),<br>&nbsp; &nbsp;JSON_EXTRACT(@myjson, '$.label'),<br>&nbsp; &nbsp;JSON_EXTRACT(@myjson, '$.*'),<br>&nbsp; &nbsp;JSON_EXTRACT(@myjson, '$.*');<br>```<\/p><p>**Sonu\u00e7:**<br>```<br>+---+---+<br>| JSON_EXTRACT(@myjson, '$') | JSON_EXTRACT(@myjson, '$.label') | JSON_EXTRACT(@myjson, '$.*') | JSON_EXTRACT(@myjson, '$.*') |<br>+---+---+<br>| {\"id\": 1, \"label\": \"C\"} &nbsp; &nbsp; &nbsp; | &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| NULL &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;|<br>+---+---+<br>```<\/p><p>##### \u00d6rnek: JSON Operat\u00f6rleri ile De\u011fer \u00c7\u0131karma<\/p><p>```sql<br>SELECT<br>&nbsp; &nbsp;myjson_col-&gt;&gt;'$',<br>&nbsp; &nbsp;myjson_col-&gt;'$',<br>&nbsp; &nbsp;myjson_col-&gt;&gt;'$.label',<br>&nbsp; &nbsp;myjson_col-&gt;&gt;'$.*',<br>&nbsp; &nbsp;myjson_col-&gt;&gt;'$.*'<br>FROM tablename;<br>```<\/p><p>**Sonu\u00e7:**<br>```<br>+---+---+<br>| myjson_col-&gt;&gt;'$' | myjson_col-&gt;'$' | myjson_col-&gt;&gt;'$.label' | myjson_col-&gt;&gt;'$.*' | myjson_col-&gt;&gt;'$.*' |<br>+---+---+<br>| {\"id\": 1, \"label\": \"C\"} | {\"id\": 1, \"label\": \"C\"} | | | NULL |<br>+---+---+<br>```<\/p><p>#### Sonu\u00e7<\/p><p>MySQL'de JSON veri t\u00fcr\u00fc, esnek ve g\u00fc\u00e7l\u00fc bir \u015fekilde JSON format\u0131ndaki verileri saklamay\u0131 ve i\u015flemeyi sa\u011flar. JSON verilerini eklemek, g\u00fcncellemek ve \u00e7\u0131karmak i\u00e7in \u00e7e\u015fitli fonksiyonlar ve operat\u00f6rler kullan\u0131labilir. Bu \u00f6zellikleri kullanarak, modern uygulamalar\u0131n ihtiya\u00e7 duydu\u011fu esnek veri yap\u0131lar\u0131n\u0131 kolayca y\u00f6netebilirsiniz. Bir sonraki yaz\u0131da g\u00f6r\u00fc\u015fmek \u00fczere!<\/p>","excerpt":"MySQL 5.7.8 ve sonraki s\u00fcr\u00fcmler, JSON (JavaScript Object Notation) veri t\u00fcr\u00fcn\u00fc destekler. Bu \u00f6zellik, JSON format\u0131ndaki verileri veritaban\u0131nda saklamay\u0131 ve bu veriler \u00fczerinde \u00e7e\u015fitli i\u015flemler yapmay\u0131 kolayla\u015ft\u0131r\u0131r. Bu yaz\u0131da, MySQL'de JSON veri t\u00fcr\u00fcn\u00fcn nas\u0131l kullan\u0131laca\u011f\u0131n\u0131, JSON verilerinin nas\u0131l eklenece\u011fini, g\u00fcncellenece\u011fini ve nas\u0131l \u00e7\u0131kar\u0131laca\u011f\u0131n\u0131 ele alaca\u011f\u0131z.","created_at":"2025-01-13 15:32:32","updated_at":"2026-09-06 21:36:50","category_id":9,"view_count":570,"reading_time":4,"status":"published","editor_choice":0,"is_editor_choice":0,"published_at":"2025-01-13 15:32:32","featured_image":"resimyok.jpg","slug":"sql-notlari-json-veri-turu-ve-islemleri","category_name":"Yaz\u0131l\u0131m","category_slug":"yazilim"}