Skip to main content

No project description provided

Project description

Jsoner

Convenient and fast adding objects to json file

Installation

pip install jsoner-lib

A simple example

from pydantic import BaseModel


class Dog(BaseModel):
    name: str
    angry: bool


class Cat(BaseModel):
    name: str
    lazy: bool


class Person(BaseModel):
    name: str
    age: str
    animals: list[Cat | Dog] | None

"""
    the so-called imaginary data that you get, for example, when parsing a website
"""
persons = [
    Person(name="Alex", age=40, animals=[Cat(name="Terminator", lazy=False)]),
    Person(name="Victor", age=24, animals=[Dog(name="Barsic", angry=True)]),
    Person(name="Michle", age=59, animals=[Cat(name="Barbon", lazy=True)]),
    Person(name="Tomas", age=42, animals=[Cat(name="Spider", lazy=False)]),
    Person(name="Robert", age=30, animals=[Cat(name="Kraul", lazy=True)]),
    Person(name="Antony", age=29, animals=[Cat(name="Green", lazy=False)])
]

jsn = Jsoner(models=[Person], filename="persons.json")


for psn in persons:
    jsn.append(psn)

jsn.save(indent=4)


## persons.json
"""
[
    {
        "name": "Alex",
        "age": "40",
        "animals": [
            {
                "name": "Terminator",
                "lazy": false
            }
        ]
    },
    {
        "name": "Victor",
        "age": "24",
        "animals": [
            {
                "name": "Barsic",
                "angry": true
            }
        ]
    },
    {
        "name": "Michle",
        "age": "59",
        "animals": [
            {
                "name": "Barbon",
                "lazy": true
            }
        ]
    },
...
...
"""

You can find examples in file /example/

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

jsoner-lib-0.5.tar.gz (3.4 kB view details)

Uploaded Source

Built Distribution

jsoner_lib-0.5-py3-none-any.whl (3.7 kB view details)

Uploaded Python 3

File details

Details for the file jsoner-lib-0.5.tar.gz.

File metadata

  • Download URL: jsoner-lib-0.5.tar.gz
  • Upload date:
  • Size: 3.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.1

File hashes

Hashes for jsoner-lib-0.5.tar.gz
Algorithm Hash digest
SHA256 47d590a55cbbf2989ca2a1a5894f350860cd0c02ec9bec40a3dce868a4180322
MD5 6983209f7b73adfd5bda476c23192544
BLAKE2b-256 192e6d4df56cdeac7180010a2b9fcb74bcd6bff8642e236d5dd1515ca7ce89f0

See more details on using hashes here.

File details

Details for the file jsoner_lib-0.5-py3-none-any.whl.

File metadata

  • Download URL: jsoner_lib-0.5-py3-none-any.whl
  • Upload date:
  • Size: 3.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.1

File hashes

Hashes for jsoner_lib-0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 88c8ebf2e65b3c4f611e71a9b00db1e8f980b9e2b5077070865db09cb0381890
MD5 bc8b1b28e232b53f0a01ab374b45c2e0
BLAKE2b-256 f601f69efd36eeedb5a828925794c9329c2a292126f26773ea43c4fb9930db8f

See more details on using hashes here.

Supported by

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