RestOC.JSON module

JSON

Wrapper for Python json module which handles custom types

class RestOC.JSON.CEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)

Bases: json.encoder.JSONEncoder

Encoder

Handles encoding types the default JSON encoder can’t handle

default(obj)

Default

Called when the regular Encoder can’t figure out what to do with the type

Parameters

obj (mixed) – An unknown object or value that needs to be encoded

Returns

str

RestOC.JSON.decode(s)

Decode

Handles decoding JSON, as a string, into objects/values

Parameters

s (str) – The JSON to decode

Returns

mixed

RestOC.JSON.decodef(f)

Decode File

Handles decoding JSON, from a file, into objects/values

Parameters

f (file-like object) – An instance of a file object with read/write methods

Returns

mixed

RestOC.JSON.encode(o, indent=None)

Encode

Handles encoding objects/values into a JSON string

Parameters

o (mixed) – The object or value to encode

Returns

str

RestOC.JSON.encodef(o, f, indent=None)

Encode File

Handles encoding objects/values into JSON and storing them in the given file

Parameters
  • o (mixed) – The object or value to encode

  • f (file-like object) – An instance of a file object with read/write methods

Returns

None

RestOC.JSON.load(filepath)

Load

Loads a data structure from a JSON file given a full or relative path to it

Parameters

filepath (str) – The path to the file to load

Returns

mixed

RestOC.JSON.store(data, filepath, indent=None)

Store

Converts an object/value into JSON and stores it in the file path given

Parameters

filepath (str) – The full or relative path to the file

Returns

None