Skip to content
Back to top
View this page
Edit this page

# xonsh.lib.lazyjson

Implements a lazy JSON file class that wraps around json data.

class xonsh.lib.lazyjson.LJNode(offsets, sizes, root)

  A proxy node for JSON nodes. Acts as both sequence and mapping.

  Parameters:
    offsets dict, list, or int

      offsets of corresponding data structure, in bytes

    sizes dict, list, or int

      sizes of corresponding data structure, in bytes

    root weakref.proxy of LazyJSON

      weakref back to root node, which should be a LazyJSON object.

  count(value) → integer -- return number of occurrences of value
  get(k[, d]) → D[k] if k in D, else d. d defaults to None.
  index(value[, start[, stop]]) → integer -- return first index of

    value. Raises ValueError if the value is not present.

    Supporting start and stop arguments is optional, but recommended.

  items() → a set-like object providing a view on D's items
  keys() → a set-like object providing a view on D's keys
  load()

    Returns the Python data structure represented by the node.

  values() → an object providing a view on D's values

class xonsh.lib.lazyjson.LazyJSON(f, reopen=True)

  Represents a lazy json file. Can be used like a normal Python dict or list.

  Parameters:
    f file handle or str

      JSON file to open.

    reopen bool, optional

      Whether new file handle should be opened for each load.

  close()

    Close the file handle, if appropriate.

  count(value) → integer -- return number of occurrences of value
  get(k[, d]) → D[k] if k in D, else d. d defaults to None.
  index(value[, start[, stop]]) → integer -- return first index of

    value. Raises ValueError if the value is not present.

    Supporting start and stop arguments is optional, but recommended.

  items() → a set-like object providing a view on D's items
  keys() → a set-like object providing a view on D's keys
  load()

    Returns the Python data structure represented by the node.

  values() → an object providing a view on D's values

xonsh.lib.lazyjson.dumps(obj, sort_keys=False)

  Dumps an object to JSON with an index.

xonsh.lib.lazyjson.index(obj, sort_keys=False)

  Creates an index for a JSON file.

xonsh.lib.lazyjson.ljdump(obj, fp, sort_keys=False)

  Dumps an object to JSON file.