JSON

decorate any function that returns python objects to return json instead

from domonic.JSON import *

@return_json
def somefunc():
    myObj = {"hi":[1,2,3]}
    return myObj

print( somefunc() )
print( is_json(somefunc()) )

convert json arrays into html tables…

import domonic.JSON as JSON

# i.e. containting flat json array of dicts... [{"id":"01","name": "some item"},{"id":"02","name": "some other item"}]

json_data = JSON.parse_file('somefile.json')
mytable = JSON.tablify(json_data)
print(mytable)

convert json arrays into csv files…

import domonic.JSON as JSON

json_data = JSON.parse_file('somefile.json')
JSON.csvify(json_data, 'data.csv')

convert csv files to json…

import domonic.JSON as JSON

json_data =JSON.csv2json("data.csv")
print(json_data)

more to come…

domonic.JSON

domonic.JSON.csv2json(csv_filepath, json_filepath=None)[source]

convert a CSV to JSON.

domonic.JSON.csvify(arr, outfile='data.csv')[source]

takes a json array and dumps a csv file

Parameters
  • arr (list) – the json array

  • outfile (list) – the output file

Returns

a csv file

Return type

str

domonic.JSON.flatten(b, delim='__')[source]

# i.e. input = map( lambda x: JSON.flatten( x, “__” ), input )

domonic.JSON.parse(json_string: str)[source]

[take a json string and return a python object]

Parameters

json_string (str) – [a json string]

Returns

[a python object]

Return type

[type]

domonic.JSON.parse_file(filepath: str)[source]

[loads a json file and returns a python object]

Parameters

filepath (str) – [path to json file]

Returns

[a python object]

Return type

[type]

domonic.JSON.stringify(data, filepath: Optional[str] = None, **kwargs)[source]

[stringify a python object]

Parameters
  • data ([type]) – [the python object]

  • filepath (str, optional) – [an optional filepath to save the stringified object] [default: None]

Returns

[the stringified object]

Return type

[type]

domonic.JSON.tablify(arr)[source]

takes a json array and returns a html table # TODO - reverse. table to json

Parameters

arr (list) – the json array

Returns

a html table

Return type

str