Skip to main content

Python Library for Nobly-Flavoured JSON

Project description

kson: Nobly-Flavoured JSON

a.k.a. kingSON

KSON is a custom data format similar to JSON but uses the crown emoji as the key-value delimiter.

This Python library provides functions to parse and serialize KSON data, following the design of Python's built-in json module.

IMPORTANT: This Library is a joke project. It's published for archive. You should not include this in your projects.

Features

  • Parse KSON strings and files into Python objects
  • Serialize Python objects into KSON strings and files

Installation

Install the KSON Library using pip:

pip install kson-irs

Usage

Parsing KSON Data from String Object

import kson

kson_data = '''
{
    "name" 👑 "John Doe",
    "age" 👑 114,
    "isPresident" 👑 false,
    "skills" 👑 ["Rust", "Syndication", "KSON"]
}
'''

data = kson.loads(kson_data)
print(data)

Such output should be observed:

{'name': 'John Doe', 'age': 114, 'isPresident': False, 'skills': ['Rust', 'Syndication', 'KSON']}

Serializing Python objects to KSON

import kson

obj = {
    "company": "IRregular Syndicate",
    "employees": [
        {
            "id": 1,
            "name": "John Doe",
            "position": "President(Good Job!)",
            "skills": ["KSON"]
        },
        {
            "id": 2,
            "name": "Jane Smith",
            "position": "Duchess",
            "skills": ["Syndication", "Python"]
        }
    ],
    "isHiring": True
}

kson_text = kson.dumps(obj, indent=4)
print(kson_text)

Such expected output shall be observed:

{
    "company" 👑 "IRregular Syndicate",
    "employees" 👑 [
        {
            "id" 👑 1,
            "name" 👑 "John Doe",
            "position" 👑 "President(Good Job!)",
            "skills" 👑 [
                "KSON"
            ]
        },
        {
            "id" 👑 2,
            "name" 👑 "Jane Smith",
            "position" 👑 "Duchess",
            "skills" 👑 [
                "Syndication",
                "Python"
            ]
        }
    ],
    "isHiring" 👑 true
}

Reading KSON from a File

import kson

with open('data.kson', 'r', encoding = 'utf-8') as file:
    data = kson.load(file)

print(data)

Writing KSON to a File

import kson

data = {
    "title": "IRoSha City",
    "population": 727,
    "coordinates": {
        "latitude": 34.0522,
        "longitude": -118.2437
    },
    "when": "you",
    "see": "it",
}

with open('city.kson', 'w', encoding='utf-8') as file:
    kson.dump(data, file, indent = 2)

Exception Handling

The library raises KSONDecodeError and KSONEncodeError exceptions for decoding and encoding errors, respectively.

import kson

try:
    # Missing Proof of Nobility and Supreme Power!
    data = kson.loads('{"key" "value"}')
except kson.KSONDecodeError as e:
    print(f"Decoding failed: {e}")

License

This project is licensed under the MIT License.

Acknowledgments

We wish to acknowledge that references to monarchies or any form of autocratic governance may be inappropriate or unsettling in certain contexts.

The KSON format's association with the crown is a stylistic choice and is not an endorsement of any specific political system or ideology.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kson_irs-0.0.2.tar.gz (5.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

kson_irs-0.0.2-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

Details for the file kson_irs-0.0.2.tar.gz.

File metadata

  • Download URL: kson_irs-0.0.2.tar.gz
  • Upload date:
  • Size: 5.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.10

File hashes

Hashes for kson_irs-0.0.2.tar.gz
Algorithm Hash digest
SHA256 356df6b5b0c99ab5eae30630f2e232f494d351b043ce15fe5befdd0c08a2b8e3
MD5 f6f323cbb38cdd9ad4b0e8789481bbec
BLAKE2b-256 bef135bec16600981e7c2f007931c90b3c9dd350e1c8e2aa438904eb82260e89

See more details on using hashes here.

File details

Details for the file kson_irs-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: kson_irs-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 6.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.10

File hashes

Hashes for kson_irs-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 d8db46faac5b49d580d35c0074ed578c9868cea17a3fbfc35987e96d255b7630
MD5 770bf895f199168b865df53147f2acdd
BLAKE2b-256 78eade7b3c7b492305cf03f8cffae12d131c6b833f5a1c2e2a3e4da6735e3ae5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page