Package json_to_relation :: Module generic_json_parser :: Class GenericJSONParser
[hide private]
[frames] | no frames]

Class GenericJSONParser

source code

object --+
         |
        GenericJSONParser
Known Subclasses:

Takes a JSON string, and returns a CSV row for later import into a relational database.

Instance Methods [hide private]
 
__init__(self, jsonToRelationConverter)
x.__init__(...) initializes x; see help(type(x)) for signature
source code
 
processOneJSONObject(self, jsonStr, row)
Given a JSON string that is one entire JSON object, parse the string into nested dicts.
source code
 
setValInRow(self, theRow, colName, value)
Given a column name, a value and a partially filled row, add the column to the row, or set the value in an already existing row.
source code
 
incArrayIndex(self, arrayIndexStack) source code
 
decArrayIndex(self, arrayIndexStack) source code
 
removeItemPartOfString(self, label)
Given a label, like employee.item.name, remove the last occurrence of 'item'
source code

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

Class Variables [hide private]
  REMOVE_ITEM_FROM_STRING_PATTERN = re.compile(r'(item)\.([^\.]*...
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, jsonToRelationConverter)
(Constructor)

source code 

x.__init__(...) initializes x; see help(type(x)) for signature

Parameters:
  • jsonToRelationConverter (JSONToRelation) - JSONToRelation instance
Overrides: object.__init__

processOneJSONObject(self, jsonStr, row)

source code 

Given a JSON string that is one entire JSON object, parse the string into nested dicts. Derive relational column names from the (possibly nested) labels. Cooperate with the parent JSONToRelations instance to build a schema of typed SQL columns. Fill the passed-in row with values from the JSON string. The following mappings from Python values are used:

   ('null', None)
       ('boolean', <true orfFalse>)
       ('number', <int or Decimal>)
       ('string', <unicode>)
       ('map_key', <str>)
       ('start_map', None)
       ('end_map', None)
       ('start_array', None)
       ('end_array', None)
       
       @param jsonStr: string of a single, self contained JSON object
       @type jsonStr: String
       @param row: partially filled array of values.
       @type row: List<<any>>

setValInRow(self, theRow, colName, value)

source code 

Given a column name, a value and a partially filled row, add the column to the row, or set the value in an already existing row. Uses the JSONToRelation instance passed to __init__() to obtain current schema.

Parameters:
  • theRow (List<<any>>) - list of values in their proper column positions
  • colName (String) - name of column into which value is to be inserted.
  • value (<any>, as per ColDataType) - the field value

removeItemPartOfString(self, label)

source code 

Given a label, like employee.item.name, remove the last occurrence of 'item'

Parameters:
  • label (String) - string from which last 'item' occurrence is to be removed

Class Variable Details [hide private]

REMOVE_ITEM_FROM_STRING_PATTERN

Value:
re.compile(r'(item)\.([^\.]*$)')