Class: Cjson

Cjson(content, isContentCJson)

Coded JSON is an extended format of JSON formatted data storage, which gives you more previledge to organize data into more structured format.

Here is an example for CJSON format:

Constructor

new Cjson(content, isContentCJson)

Coded JSON is an extended format of JSON formatted data storage, which gives you more previledge to organize data into more structured format.

Here is an example for CJSON format:

Parameters:
Name Type Description
content

Can be path to the CJSON file. In this case the second param can be optional

isContentCJson

Set this true if you are passing raw CJSON content as content

Source:
Example
{
    "source": $import "./source.json",
    "target": {
        "fruit": "Apple",
        "size": "Large",
        "color": "Red",
        "secColor": $.target.color,
        "colorList": [ $.target.color, $.target.secColor ],
        // You can add comments like this
        "digitCheck": 1.5,
        "digitImport": $.target.digitCheck,
        "digitArrayImport": [ $.target.digitCheck, $.target.digitImport ]
    }
}


The above `CJSON` snipped will be deserialized in JSON format and can be used
as same as other JSON files.

For other details, please refer to official page: https://subhendushekhar.github.io/cjson/

Members

replace

Replace a JPath to a specified value. The function context is of JSON and cannot be used in CJSON context.

In order to use this in CJSON context, follow below steps:

  1. Create CJson object
  2. Deserialize
  3. Deserialize
  4. cjson.json?.replace("$.jpath", value, object)
Source:

Methods

decodeImport(lineItem)

Decodes import keyword

Parameters:
Name Type Description
lineItem

Comma separated line item in string

Source:

decodeKeywords()

Root function for decoding keywords Need to improve performance. v1.0.0

Source:

decodeRelativePaths()

Import functions path to relative file is deocded. Modifies content

Source:

decodeSingleLineComment(lineItem)

Identifies comment lines. Can identify multiple lined comments

Parameters:
Name Type Description
lineItem

Comma separated line item in string

Source:

deserialize()

Deserializes the keywords.

Source:
Returns:

JSON if no errors. Else undefined

deserializeAsString()

Deserializes CJSON content and returns content as string.

Content will be of pure JSON content and can be parsed as JSON

Source:
Returns:

JSON equivalent of CJSON content in string

getFilePath(lineItem)

Returns file path from import keyword

Parameters:
Name Type Description
lineItem

Comma separated line item in string

Source:
Returns:

File path in string

inject(injectingObj)

Use this for injecting variable at runtime.

Value need to be replaced can be stored with a key like <key>.

Pass the value as json object in injectingObj

Parameters:
Name Type Description
injectingObj

Runtime values to be injected in json format

Source:
Returns:

JSON if no errors. Else undefined

remove(key)

Removes a key:value from the CJSON context. Key will be JPath in $.full.path format

The function automatically deserializes before removing. So, no need to explicitely deserialize it.

Parameters:
Name Type Description
key

JPath to the key to be removed.

Source:
Returns:

Resultant content in JSON object

(static) toString(obj)

Converts JSON object to string. Just a wrapper over JSON.stringify()

Parameters:
Name Type Description
obj

JSON object

Source:
Returns:

JSON string