Introduction

PowerJSON

PowerJSON is the data format that improved from JSON, It completely uses the syntax of JSON and JavaScript, and adds many new features to it, which solves some of the long-standing problems of JSON. For example, it supports single quoted string, multi-line string, comment, operator, import file, import PJSON file, etc.

The specific content will be introduced below πŸŽ‰

Start

Look at the PowerJSON and JSON code first:

//powerjson
{
    helloText: 'hello world!'
}

//json
{
    "helloText": "hello world!"
}

As you can see in this code, helloText does not need to include double quotes in PowerJSON, and its value also supports calls in the form of single quotes.

The top is just a very simple example, so let's think about some complicated scenes.

If my helloText is done in another hello.txt text file, this is not possible in JSON, but in PowerJSON, you can implement it with new File(path).

{
    helloText: new File('./hello.txt')
}

Alternatively, you can replace \n in JSON with a multi-line string from PowerJSON.

{
    helloText: `
        Hello
        World
    `
}

Multi-line strings in PowerJSON take the form of JavaScript, just wrap a string with `.

More

Similarly, PowerJSON also provides the functionality of comments and operators. If you want to write some comments to illustrate the usefulness of some fields, just write:

{
    //this is our helloText
    /*
        welcome to powerjson!
     */
    helloText: `
        Hello
        World
    `
}

If you want to calculate how many milliseconds there are in 10 days:

{
    tenDayTime: 1000 * 60 * 60 * 24 * 10
}

Are you ready?

We just briefly introduced the difference between PowerJSON and JSON -- the rest of this tutorial will cover these and other advanced features in more detail, so be sure to read the full tutorial! πŸ‘