Skip to main content
CJSON Logo

Coded Javascript Object Notation


For Python


CJSON is a data file format(inspired from JSON), but supports logical expressions too. Having extended language support to NodeJS, Python and Java, users has experienced data reusability. For features and examples, please refer to this documentation as base document.


Python Tag
Test Status




Installation

pip install codedjson

Examples

Importing a JSON file in CJSON file

file.cjson

{
    "source": $import "path/to/source.json",
    "target": {
        "fruit": "Apple",
        "size": "Large",
        "color": "Red"
    }
}

Code

    from cjson import Cjson
    cjson = Cjson(file/path/to/file.cjson);
    var b = cjson.deserialize();

Output

{
    "source": {
        // source.json content
    },
    "target": {
        "fruit": "Apple",
        "size": "Large",
        "color": "Red"
    }
}

Calling relative keys using JPATH

Below example shows color variable is calling data from fruit variable

file.cjson

{
    "target": {
        "fruit": "Orange",
        "size": "Medium",
        "color": $.target.fruit
    }
}

Code

    from cjson import Cjson
    cjson = Cjson(file/path/to/file.cjson);
    var b = cjson.deserialize();

Output

{
    "target": {
        "fruit": "Orange",
        "size": "Medium",
        "color": "Orange"
    }
}

Dynamic variable injection

file.cjson

{
    "target": {
        "types": "asd",
        "fruit": <fruit>,
        "quantity": <quantity>,
    },
    "jsonInjection": <jsonTypeData>
}

Code

    cjson = Cjson(variable_injection)

        injec_data = {
            "fruit": "apple",
            "quantity": 1,
            "jsonTypeData": {
                "secondaryData": {
                    "type": "fruit",
                    "seeds": "yes"
                }
            }
        }

    data = cjson.inject(injecting_obj=injec_data)

Output

{
    "target": {
        "types": "asd",
        "fruit": "apple,
        "quantity": 1,
    },
    "jsonInjection": {
        "secondaryData": {
            "type": "fruit",
            "seeds": "yes"
        }
    }
}

Single/ Multiple line comments

For single line comments, use //

For multi line comments, use like below:

// This is first line comment
// This is the second one

{
    "name": "Amrut" // This is not allowed
}

Release files for codedjson 2.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for codedjson 2.0.0
File Size Uploaded
codedjson-2.0.0.tar.gz 8.2 kB Details

Release files / codedjson-2.0.0.tar.gz

Download URL codedjson-2.0.0.tar.gz
Size 8.2 kB
Tags Source
SHA-256 checksum
How to use checksums
698aa0bd2879b95f6beab6eebba50b07e486e930f28787d974cd36cdb79b17be
BLAKE2b-256 checksum
How to use checksums
909af9619d10f23868c5cdf87eb8388c7b1362b52772f28c4445c0baf1a48e7b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.12.0

Release history Release notifications | RSS feed

This release

2.0.0 This release

1 release file

1.3.2

1 release file

1.2.0

1 release file

1.1.1

1 release file

1.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page