{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Синтаксис JSON"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'name': 'Сергей', 'age': 48, 'country': 'Russian'}"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "{\"name\": \"Сергей\", \"age\": 48, \"country\": \"Russian\"}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Сериализация объекта Python в формат JSON и записи его в файл"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "import json\n",
    "infa = {\"name\": \"Сергей\", \"age\": 48, \"country\": \"Russian\"}\n",
    "with open(\"myfail.json\", \"w\", encoding=\"UTF-8\") as file:\n",
    "    json.dump(infa, file, indent=4, ensure_ascii=False)   "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Десериализация данных из JSON-файла и преобразования их в объекты Python"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'name': 'Сергей', 'age': 48, 'country': 'Russian'}\n"
     ]
    }
   ],
   "source": [
    "import json\n",
    "\n",
    "with open(\"myfail.json\", \"r\", encoding=\"UTF-8\") as file:\n",
    "    data=json.load(file)\n",
    "print(data)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": ".venv",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
