JSON Tutorial

From OpenSemanticWorld
Item:OSWf1df064239044b8fa3c968339fb93344 /
Revision as of 08:52, 27 June 2023 by Admin (talk | contribs) (Install package: OSW Docs - Core)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
JSON Tutorial [OSWf1df064239044b8fa3c968339fb93344]
ID OSWf1df064239044b8fa3c968339fb93344
UUID f1df0642-3904-4b8f-a3c9-68339fb93344
Label JSON Tutorial
Machine compatible name JsonTutorial
OSW2055124fe7b344148a1baad537bf8e35.png
Statements (outgoing)
Statements (incoming)
Keywords

Description

Covers basics about JSON-Documents

Item
Type(s)/Category(s) Tutorial
CreativeWork
Article
Tutorial
Prerequisites (required)
Prerequisites (optional)
Follow-up (recommended) JSON-SCHEMA Tutorial
JSON-LD Tutorial

View as slide show

JSON Documents: Basics

What is a JSON?

  • A JSON itself is a JSON object, marked by [1]
{}

JSON Documents: Key-Value-Pairs

  • A JSON object defines key(word):value pairs.
  • Keys are formatted as strings, marked by quotation marks ("").
{
    "key": "value"
}

JSON Documents: Data types

  • The key is always a string
  • The value can be a string, a number, a boolean or null
  • Additional data types are only possible by referencing them as external resources
{
    "key": "value",
    "string": "any string value",
    "number": 1.0,
    "bool": true,
    "empty": null,
    "image": "https://my.cloud/image-1.png"
}

JSON Documents: Subobjects

  • The value can also be a JSON document (object) itself
  • A nested object can have the same key-value pairs as the root document
  • There is no limit in the nesting depth
{
    "key": "value",
    "string": "any string value",
    "number": 1.0,
    "bool": true,
    "empty": null,
    "object": {
        "has": "it's own key-value-pairs"
    }
}

JSON Documents: Arrays

  • The value can also be an array (list)
  • An array can contain any element, including objects and nested arrays
{
    "key": "value",
    "string": "any string value",
    "number": 1.0,
    "bool": true,
    "empty": null,
    "object": {
        "has": "it's own key-value-pairs"
    },
    "array": [
        "a list", 
        {"of": "any"}, 
        ["item1", 1.0, true]
    ]
}

JSON Documents: Pointer (1)

Pointer allow reference to

  • An object within the JSON document
{
    "firstname": "Susan",
    "surname": "Birch",
    "kids": ["Anne", "Tom"],
    "emergency_contact": {
        "$ref": "#/kids/0"
    }    
}

Syntax [2]:

# - the whole document = self-reference

#/kids - the value of the key "kids"

#/kids/0 - the first item within the array "kids"

JSON Documents: Pointer (2)

Pointer allow reference to

  • An object within the JSON document
  • An external JSON document
{
    "firstname": "Susan",
    "surname": "Birch",
    "partner": {
        "$ref": "http://www.personaldata.com/walter.birch.json"
    }
}

JSON Documents: Next


📎 Select files (or drop them here)... 📷 Camera
    jsondata
    required_predecessor
    Empty array
    optional_predecessor
    Empty array
    recommended_successor
    "Item:OSWf4a9514baed04859a4c6c374a7312f10"
    "Item:OSW911488771ea449a6a34051f8213d7f2f"
    type
    "Category:OSW494f660e6a714a1a9681c517bbb975da"
    uuid"f1df0642-3904-4b8f-a3c9-68339fb93344"
    name"JsonTutorial"
    label
    text"JSON Tutorial"
    lang"en"
    description
    text"Covers basics about JSON-Documents"
    lang"en"
    image"File:OSW2055124fe7b344148a1baad537bf8e35.png"
    Cookies help us deliver our services. By using our services, you agree to our use of cookies.