What is JSON File ?

2021. 9. 9. 00:02·Computer Science/Terminology and Concepts

JSON stands for JavaScript Object Notation. A JSON file has .json as its extension and the data inside are represented in a key:value pair, just like a traditional JavaScript object.

{
  "key1": "value1",
  "key2": "value2",
  "key3": "value3",
  "key4": 7,
  "key5": null,
  "favFriends": ["Kolade", "Nithya", "Dammy", "Jack"],
  "favPlayers": {"one": "Kante", "two": "Hazard", "three": "Didier"}
}

Accepted JSON Data Types

JSON can be defined in an object or an array, which might take in several objects.

So, objects and arrays are automatically acceptable data types in JSON. Other data types that it supports are boolean, null, and string.

Data types such as undefined, function, and date are not supported by JSON.

 

JSON syntax rules to know:

  • All the data in the file must be surrounded by curly braces if you're representing it as an object, and in square brackets if it is an array.
  • Single quotes are not allowed
  • The key in each JSON must be unique and must be in double quotes
  • Numbers must not be enclosed in double-quotes, otherwise they will be treated as strings.
  • The null data type must not be enclosed in double-quotes.
  • Boolean values can only be true or false.
  • Each key:value pair must be terminated with a comma except for the last item
  • A particular object inside an array must be terminated by a comma, too.

How JSON Data is Sent to the Client (Browser)

JSON was created out of the need to send data from the server (a database, for example) to the client (browsers) in real-time.

In JavaScript, JSON.parse() converts JSON data to objects and JSON.stringify() converts an object's key:value pair to JSON data.

 

<h2>Here is the Data from the JSON:</h2> 
<div id="json"></div>
 const JSONData = {
    "key1": "value1",
    "key2": "value2",
    "key3": "value3",
    "key4": 7,
    "key5": null,
    "favFriends": ["Kolade", "Nithya", "Dammy", "Jack"],
    "favPlayers": {"one": "Kante", "two": "Hazard", "three": "Didier"}
}

const JSONString = JSON.stringify(JSONData)
const JSONDisplay = document.querySelector("#json")
JSONDisplay.innerHTML = JSONString

JSONString: String type

 

const JSONData =
     '{"name": "Kolade", "favFriends": ["Kolade", "Nithya", "Rocco", "Jack"], "from": "Africa"}';

   try {
     const JSONString = JSON.parse(JSONData);
     const JSONDisplay = document.querySelector("#json");
     JSONDisplay.innerHTML = JSONString.name + ", [" + JSONString.favFriends + "], " + JSONString.from;
   } catch (error) {
     console.log("Cannot parse the JSON Data");
   }

JSONString: Object Type

Why use JSON Type ?

JSON (JavaScript Object Notation) is most widely used data format for data interchange on the web. JSON is a lightweight text based, data-interchange format and it completely language independent. It is based on a subset of the JavaScript programming language and it is easy to understand and generate. 

We use JSON because it's extremely lightweight to send back and forth in HTTP requests and responses due to the small file size. It's easy to read compared to something like XML since it's much cleaner and there's not as many opening and closing tags to worry about.

 

 

 

Source from 

- https://www.freecodecamp.org/news/what-is-a-json-file-example-javascript-code/

- https://www.geeksforgeeks.org/json-data-types/

- https://www.prokurainnovations.com/json/

'Computer Science > Terminology and Concepts' 카테고리의 다른 글

DOM 트리의 탐색  (0) 2022.12.13
dependencies version in package.json  (0) 2021.10.16
Service worker  (0) 2021.09.03
CDN  (0) 2021.08.01
PWA  (0) 2021.08.01
'Computer Science/Terminology and Concepts' 카테고리의 다른 글
  • DOM 트리의 탐색
  • dependencies version in package.json
  • Service worker
  • CDN
JTB
JTB
웹/앱 개발 정보를 공유하고 있습니다.
  • JTB
    JTechBlog
    JTB
  • 전체
    오늘
    어제
    • All About Programming;) N
      • Computer Science
        • Terminology and Concepts
        • Network
        • Operating System
        • Database
        • Data Structure
      • Frontend
        • Javascript Essentials
        • Perfomance Optimization
        • JS Patterns
        • Next.js
        • Flutter
      • Backend
        • Node.js
      • DevOps
        • Docker & Kubernetes
      • Coding Test N
        • LeetCode N
        • Programmers
      • Tech Books & Lectures
        • Javascript_Modern JS Deep d..
        • Network_IT 엔지니어를 위한 네트워크 입문
      • Projects
        • PolyLingo_2025
        • Build Your Body_2024
        • JStargram_2021
        • Covid19 Tracker_2021
        • JPortfolio_2021
      • BootCamp_Codestates
        • TIL
        • TILookCloser
        • Pre Tech Blog
        • IM Tech Blog
        • Daily Issues and DeBugging
        • First Project
        • Final Project
        • Sprint Review
        • Good to Know
        • Socrative Review
        • HTML &amp; CSS
  • 블로그 메뉴

    • 홈
    • 태그
    • 방명록
  • 링크

    • 글쓰기
    • 관리
  • 공지사항

  • 인기 글

  • 태그

    Time complexity and Space complexity
    DOM
    VoiceJournal
    Operating System
    TCP/IP
    Threads and Multithreading
    프론트엔드 성능 최적화 가이드
    딥다이브
    js pattern
    database
    need a database
    Shared resources
    자바스크립트 딥다이브
    leetcode
    indie hacker
    polylingo
    Network
    testing
    How memory manage data
    스코프
    모던 자바스크립트 Deep Dive
    Binary Tree BFS
    JavaScript
    Data Structure
    mobile app
    CPU scheduling algorithm
    이벤트
    자바스크립트
    structure of os
    커리어
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.5
JTB
What is JSON File ?
상단으로

티스토리툴바