Package tlib :: Package base :: Module JsonHelper :: Class JsonHelper
[hide private]
[frames] | no frames]

Class JsonHelper

source code

   object --+    
            |    
Helper.Helper --+
                |
               JsonHelper

Helper class to manipulate the data in Json format

Instance Methods [hide private]
 
__init__(self, data, schema=None)
Constructor for class
source code
 
validateBySchema(self, schema=None)
Check if Json string is compliant with schema
source code
 
getValuesByJSONPath(self, jpath)
Get all values using JSONPath
source code
 
getValueByJSONPath(self, jpath)
Get the first value using JSONPath
source code
 
normalizeJSONPath(self, jpath)
Get the normalized JSONPath
source code
 
toString(self, pretty_print=True)
Print Json data in a nice format
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Class Variables [hide private]
  _obj = None
  _schema = None

Inherited from Helper.Helper: logger

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, data, schema=None)
(Constructor)

source code 

Constructor for class

Parameters:
  • data - the json string to be processed (alternatively, it can the location of the json file)
  • schema - path to the json schema file
Overrides: object.__init__

validateBySchema(self, schema=None)

source code 

Check if Json string is compliant with schema

Returns : (bool) whether schema validation is passed

getValuesByJSONPath(self, jpath)

source code 

Get all values using JSONPath

Args:
    jpath : JSON-path used to search for values

For more details about the JSON-Path, please refer to http://goessner.net/articles/JsonPath/

Returns : all matching values from JSONPath search in a list 

getValueByJSONPath(self, jpath)

source code 

Get the first value using JSONPath

Args:
    jpath : JSON-path used to search for values

For more details about the JSON-Path, please refer to http://goessner.net/articles/JsonPath/

Returns : the first matching value from JSONPath search result 

normalizeJSONPath(self, jpath)

source code 

Get the normalized JSONPath

Args:
    jpath : JSON-path used to fetch normalized path

For more details about the JSON-Path, please refer to http://goessner.net/articles/JsonPath/

Returns : normalized JSONPath

toString(self, pretty_print=True)

source code 

Print Json data in a nice format

Args:
    pretty_print : do you want to be pretty?

Returns : formatted Json string