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

Class JsonHelper

   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
 
getValueByJSONPath(self, jpath)
Get the first value using JSONPath
 
getValuesByJSONPath(self, jpath)
Get all values using JSONPath
 
normalizeJSONPath(self, jpath)
Get the normalized JSONPath
 
toString(self, pretty_print=True)
Print Json data in a nice format
 
validateBySchema(self, schema=None)
Check if Json string is compliant with schema

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)

 

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__

getValueByJSONPath(self, jpath)

 

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 

getValuesByJSONPath(self, jpath)

 

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 

normalizeJSONPath(self, jpath)

 

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)

 

Print Json data in a nice format

Args:
    pretty_print : do you want to be pretty?

Returns : formatted Json string

validateBySchema(self, schema=None)

 

Check if Json string is compliant with schema

Returns : (bool) whether schema validation is passed