File standards -

JSON, HTML, CSV

JSON

What is this?

In computing, JavaScript Object Notation or JSON is an open-standard file format that uses human-readable text to transmit data objects consisting of attribute-value pairs and array data types (or any other serializable value). It is a very common data format used for asynchronous browser–server communication, including as a replacement for XML in some AJAX-style systems.

In other words...

JSON is a standard for communication with data in human-readable format. It's similar to Python's dictionaries with very little differences. JSON keys have to be only strings and it's values must be simple (serializible) - int, float, str, list, dict

  • How do you understand the word "standard"?
  • Why is it good to have standards?
  • What does JSON give us?

Python <3 JSON

import json


def read_json():
    with open('colors.json', 'r') as f:
        data = json.load(f)

    return data



def write_json():
    data = read_json()

    dic = {"yellow": 125}
    data.update(dic)

    with open('colors.json', 'w') as f:
        json.dump(data, f)

HTML

Hypertext Markup Language (HTML) is the standard markup language for creating web pages and web applications.

 Web browsers receive HTML documents from a web server or from local storage and render them into multimedia web pages. HTML describes the structure of a web page semantically and originally included cues for the appearance of the document.

.html files

  • All HTML documents must start with a document type declaration: <!DOCTYPE html>.
  • The HTML document itself begins with <html> and ends with </html>.
  • The <head> element is a container for all the head elements.
  • The visible part of the HTML document is between <body> and </body>.
<!DOCTYPE html>
<html>
<head>
  <title>First HTML</title>
</head>
<body>

<h1>My First Heading</h1>

</body>
</html>

Common tags

  • <head>...</head>
  • <body>...</body>
  • Container: <div>...</div>
  • Headings: h, h1, h2, h3...
  • Paragraphs/simple text: <p>text</p>
  • Lists:
    <ul>
      <li>First element</li>
      <li>Second element</li>
    </ul>
  • Images: <img />
  • More here.

CSV

  • In computing, a comma-separated values (CSV) file stores tabular data (numbers and text) in plain text. Each line of the file is a data record. Each record consists of one or more fields, separated by commas.

  • The CSV file format is not standardized. The basic idea of separating fields with a comma is clear, but that idea gets complicated when the field data may also contain commas or even embedded line-breaks.

  • Similar to Excel tables

  • Used mainly in statistics for simple datasets

Coding time!

JSON, HTML, CSV

By Hack Bulgaria

JSON, HTML, CSV

  • 1,014