DEV Community

LunaStev
LunaStev

Posted on

1

WSON (Web Simple Object Notation)

WSON is a new data serialization format designed to address the shortcomings of JSON and YAML.

GitHub

Syntax Definition

1. Basic Structure

  • The contents of a WSON file are enclosed in curly baces {}, which represent an object.
  • An object consists of key-value pairs.
  • Keys and values are separated by either a colon (:) or an equals sign (=).

2. Comments

  • Comments begin with // or # and are written on a single line.
  • Comments apply until the end of the line.
  • Multi-line comments are not supported; for comments spanning multiple lines, add // or # at the start of each line.

3. Object

  • An object is enclosed in curly barces {} and contains key-value pairs.
  • You can use either : or = between keys and values, and both symbols can be mixed within the same object
  • Each attribute is separated by a comma ,.
  • Objects can be nested within other objects.

Example:

{
    status: "success",
    code = 200,
    user = {
        id: 123,
        name: "John Doe"
    }
}
Enter fullscreen mode Exit fullscreen mode

4. Array

  • Arrays are enclosed in square brackets [], and elements are separated by commas ,.
  • Array elements can include objects, strings, numbers, and other data types.
  • In WSON, arrays can be nested within objects, and arrays can contain other arrays or objects.

Example:

tasks: [
    {
        task_id: 1,
        title: "Complete project report"
    },
    {
        task_id: 2,
        title: "Review team feedback"
    }
]
Enter fullscreen mode Exit fullscreen mode

5. Key-Value Pair

  • Attribute names are strings and are followed by either : or =, with the value placed immediately after.
  • Value types include strings, numbers, booleans, objects, and arrays.
  • Strings are enclosed in double quotes ".
  • Numbers are used without quotes and can be integers or floating-point values.

Example:

name: "John Doe"
age = 25
Enter fullscreen mode Exit fullscreen mode

6. Data Types

  • String: Text enclosed in double quotes ".
"hello world"
Enter fullscreen mode Exit fullscreen mode
  • Number: An integer or floating-point value.
42
3.14
Enter fullscreen mode Exit fullscreen mode
  • Boolean: Uses true or false valuse.
is_active = true
Enter fullscreen mode Exit fullscreen mode
  • Object: Key-value pairs enclosed in curly braces {}.
  • Array: A list of elements enclosed in square brackets [].

7. Example Explanation

{
    // Status code and message information
    status: "success",
    code: 200,
    message: "Data retrieved successfully",

    user = {
        id = 123,
        name: "John Doe",
        email: "john@example.com",
        age: 25  # User age
    },

    tasks: [
        {
            task_id: 1,
            title: "Complete project report",
            status: "in-progress",
            due_date: "2024-10-15"
        },
        {
            task_id: 2,
            title: "Review team feedback",
            status: "pending",
            due_date: "2024-10-20"
        }
    ]
}
Enter fullscreen mode Exit fullscreen mode

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (0)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay