Skip to main content

Make Your Json Lovely

Project description

Lovely Json

Features

1. Direct Access to Key Value

**take a look at example to run in code **
This example uses "sample_api.json" so does the following examples"

1-(1). load json

json_data =  open("./sample_api.json", encoding="utf-8", mode='r')

j_sample = Lovely_Json(json.load(json_data), name = 'api_response')	

You need to load json file as you did before in this case too
It was intentionaly designed like this to use at ".json" file and
for json response for servers

In case of using serval jsons, names are recommanded

1-(2). use dot operators to directly get key values

To get data by key

# Lovely_Json :
print(j_sample.Depth4.depth4_item1) # prints "Python"

# Just Json :
original = json.load(open("./sample_api.json", encoding="utf-8", mode='r'))
original["Depth1"]["Depth2"]["Depth3"]["Depth4"]["depth4_item1"] # prints "Python"

To get data, you only need to know the key in the way to make sure what you are finding for. Take a look at image I made To show sample_api.json as graphs
sample_api_grpah_img

To get Value That are dict, You could directly get it by dot operators (getattr)

print(j_sample.Depth4) # prints {"depth4_item1" : "Python","depth4_item2" : "Haskell"}

But If you want to get Value that isn't dict, You should go through upper key and then get it by dot operators

print(j_sample.Depth4.depth4_item1) # prints "Python"

You could also do by this

print(j_sample.Depth1.depth4_item1) # prints "Python"
print(j_sample.Depth2.depth4_item1) # prints "Python"
print(j_sample.Depth3.depth4_item1) # prints "Python"
print(j_sample.Depth4.depth4_item1) # prints "Python"

2. Access to List of Key Value

# to access item in list, returns list of value of key, "id"
print(j_sample.in_list(key = 'data').id , end='\n\n')
# ---> prints [111, 222, -333]
# and if you have conditions about 'id'
print(j_sample.in_list(key = 'data', if_ ='id', is_ = (lambda x:x>0)).id , end='\n\n') 
# --->prints [111, 222]
# also you could use other key's value of conditions
print(j_sample.in_list(key = 'data', if_ ='type', is_ = (lambda x:x =='articles')).id, end='\n\n')
# --->prints [111, -333]

"if_" and "is_" were desinged to be used like SQL Where syntex, if_ takes key, wher you want to make conditions is_ takes lamda or method that returns Bool ( True, False) to check the value fit in what you required

add

lovely_json was made to make ease access of json data, when developing systems or services.
There will be continuous update for useful methods and speed improvements,
But using conventional ways will make much more speed improvements.

So Think lovely_json as a tool when you use before releasing, like a rough sketch

Thank You!

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

lovely_json-0.0.1.tar.gz (2.5 kB view details)

Uploaded Source

Built Distribution

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

lovely_json-0.0.1-py3-none-any.whl (3.3 kB view details)

Uploaded Python 3

File details

Details for the file lovely_json-0.0.1.tar.gz.

File metadata

  • Download URL: lovely_json-0.0.1.tar.gz
  • Upload date:
  • Size: 2.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.3

File hashes

Hashes for lovely_json-0.0.1.tar.gz
Algorithm Hash digest
SHA256 b78cc5af704bd8ef6e0a93138df55145c994bf5ea7dedcf383b71af134a51db4
MD5 cff9da25b3da1a0be38d85a93765194a
BLAKE2b-256 f69e440668d4873bf79a2331ecc0e99162fdd0e45d33842fb8ac1e8b99ac0bd6

See more details on using hashes here.

File details

Details for the file lovely_json-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: lovely_json-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 3.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.3

File hashes

Hashes for lovely_json-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5e9276e26a17a88ffdcc572be0f9280bb1eeddb9132ecc24b3d3fa6b1b92f81c
MD5 9754887469b9930f5bcc22690f960fa8
BLAKE2b-256 19845c2be0af73b8ed36e06edc79178f46f033d1a9749f1448bc54e4214df000

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