Skip to main content

simple json conversion implements using stack structure and recursive method

Project description

FullJSON

The package is for JSON conversion in Python enviroment.

JSON TypeJSON Type ExamplePython TypePython Type Value
object{}dicttype({})
array[]listtype([])
string"example"strtype('example')
number1/1.0int/floattype(1)/type(1.0)
"true"trueTruetype(True)
"false"falseFalsetype(False)
"null"nullNonetype(None)

Implements

Convert a JSON string into a JSON object

JSON.parse(value) is based on stack structure. There are three stacks in the program, stack stack for characters, class_stack stack for list and dict, keyvalue_stack stack for name/value pair. Scan each character in the string, do the following:

  1. If is [, put type/value into class_stack stack
  2. If is {, put type/value into the class_stack stack, and put an empty key/value pair (named border) into the keyvalue_stack stack
  3. If is,, according to class_stack stack top type (list and dict), list is to operate on the top of the class_stack stack and call its append method, dict is pushed into the keyvalue_stack stack
  4. If is ], popping all the elements on the top of the stack stack until it encounters [
  5. If is }, pop the keyvalue_stack stack and pop all the elements on the top of the stack until it encounters border
  6. If is :, operate on the top of the keyvalue_stack stack and modify the value in the key/value pair
  7. Other, put characters into the stack stack

Convert JSON values to JSON strings

JSON.stringify(value) is using recursive method.

  1. If it is a basic type in Python (number, string, bool, None), return the corresponding string (1/1.0, "example", true/false, null)
  2. If it is list and dict, repeat step 1 for each element in the list and dict
  3. Others, It is a class, consider as a dict type, terating over member variables of a class, do the same action as step 1

Installation

pip install fulljson 

Examples

  • Convert a JSON string into a JSON object.
>>> from fulljson import JSON
>>>
>>> value = '["foo", {"bar": ["baz", null, 1.0, 2, true]}]'
>>> print(JSON.parse(value))
['foo', {'bar': ['baz', None, 1.0, 2, True]}]
>>>
  • Convert JSON values to JSON strings.
>>> from fulljson import JSON
>>>
>>> value = ["foo", {"bar": ["baz", None, 1.0, 2, True]}]
>>> print(JSON.stringify(value))
["foo",{"bar":["baz",null,1.0,2,true]}]
>>>
  • Format JSON object or JSON strings
>>> from fulljson import JSON
>>>
>>> value = [{'foo': 'new 0', 'index': None}, "sat", {'bar': 'new 2', 'index': [1, True]}]
>>> print(JSON.format(value))
[
    {
        "foo":"new 0",
        "index":null
    },
    "sat",
    {
        "bar":"new 2",
        "index":[
            1,
            true
        ]
    }
]
>>>

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

fulljson-0.0.53.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

fulljson-0.0.53-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

Details for the file fulljson-0.0.53.tar.gz.

File metadata

  • Download URL: fulljson-0.0.53.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.18.4 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.41.0 CPython/3.5.4

File hashes

Hashes for fulljson-0.0.53.tar.gz
Algorithm Hash digest
SHA256 1d0582d654f49448c878f7436670dee3d220001c818ec6ab4cd988a87b251465
MD5 56d3fe1274efe8c624603be36aa4dd47
BLAKE2b-256 9e80b570d3ae2b06c06ee38314c89f3c9df5016ce2e711bb9e21dc19d3ef7b70

See more details on using hashes here.

File details

Details for the file fulljson-0.0.53-py3-none-any.whl.

File metadata

  • Download URL: fulljson-0.0.53-py3-none-any.whl
  • Upload date:
  • Size: 8.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.18.4 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.41.0 CPython/3.5.4

File hashes

Hashes for fulljson-0.0.53-py3-none-any.whl
Algorithm Hash digest
SHA256 f7c10f354c2b3c07a223d4594ff76683187ea030daa9cedb85079a43ecbc471c
MD5 78a550952b171d9a02a596bb00fc41c1
BLAKE2b-256 86178756021bedb54f4f11028865a4120b96cb272c95d6fa09935a0ad99f904d

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