‘jsondata.JSONTree’ - Module

The JSONTree module provides features for in-memory JSON structures.

The provided features comprise:

  • The construction and printout of tree formatted structures for screen analysis.
  • Comparison of JSON strings as tree structures.

Constants

Operations modes

  • _interactive = False: Activates interactive mode.

Diff Mode

  • DIFF_FIRST = 0: break display of diff after first
  • DIFF_ALL = 1: list all diffs

Displayed Character Set

  • CHARS_RAW = 0: display character set as raw
  • CHARS_RAW = 1: display character set as str
  • CHARS_RAW = 2: display character set as utf/utf-8

Line-Overflow

  • LINE_CUT = 0: force line fit
  • LINE_WRAP = 1: wrap line in order to fit to length

JSONTree

class jsondata.JSONTree.JSONTree(**kargs)[source]

Variables

  • self.difflist : reaulting differences
  • self.scope: scope of differences
  • self.linefit: handle overflow
  • self.linewidth: line width
  • self.charset: character set
  • self.indent: indention steps

Methods

__init__

JSONTree.__init__(**kargs)[source]

Create an object for the tree representation.

Args:

**kargs: Parameter specific for the operation,

scope:

  • all: Display all diffs.
  • first: Display first diff only.

default:=first

charset:

  • raw: Use ‘raw’.
  • str: Use ‘str’.
  • utf: Use ‘utf’.

default:=raw

debug:

Add developer information.

linefit:

  • cut: Cut lines to length.
  • wrap: Split lines to length.

default:=wrap

indent=#numchars:

Number of characters for indentation.

linewidth=#numchars:

Length of lines.

verbose:

Add progress and status dialogue output.
Returns:
When successful returns ‘True’, else raises an exception.
Raises:
passed through exceptions:

printDiff

JSONTree.printDiff()[source]

Prints out the resulting list of differences.

Args:
ffs.
Returns:
When successful returns tree represantation.
Raises:
passed through exceptions:

fetchDiff

JSONTree.fetchDiff(n0, n1, p=[], dl=0)[source]

Recursive tree compare for Python trees as used for the package ‘json’.

Finds diff in native Python trees assembled by the standard package ‘json’ and compatible, e.g. ‘ujson’.

  • leveltop
  • levelbottom
  • delta (for containers)
  • scope(all, first)
  • linewidth
  • displaycharset (str,utf)
  • pathonly

Args:

n0:

JSON string of type ‘str’, or ‘unicode’

n1:

JSON string of type ‘str’, or ‘unicode’

p=[]:

Result entries for each difference:
{'n0':n0,'n1':n1,'dl':dl,'p':p[:]}
  1. first JSON data
  2. second JSON data
  3. diff count increment value
  4. current diff including path

List of differences as of:

  1. non equal types are different: type(n0) != type(n1)

  2. equal types, both list: type(n0) is list

    1. length is different: len(n0.keys()) != len(n1.keys())
    2. at leats one item is different: n1.get(ni) and v != n1[ni]
  3. equal types, both dict: type(n0) is dict and type(n1) is dict

    1. length is different: len(n0.keys()) != len(n1.keys())
    2. at leats one item is different: n1.get(ni) and v != n1[ni]

default:=0

Returns:
When no diffs returns True, else False or raises an exception. The resulting differences are contained in the provided list parameter ‘p’. When not provided the resulting list is suppressed.
Raises:
passed through exceptions:

Exceptions

class jsondata.JSONTree.JSONTreeException[source]

Error in JSONTree.