Domonic: 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…

from domonic.JSON import *

# 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…

from domonic.JSON import *

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

convert csv files to json…

from domonic.JSON import *

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

more to come…

domonic.JSON

class domonic.JSON.JSON[source]

A class containing JSON utils

static csv2json(csv_filepath, json_filepath=None)[source]

convert a CSV to JSON.

static 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

static flatten(b, delim='__')[source]

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

static 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
domonic.JSON.return_json(func)[source]

decorate any function to return json instead of a python obj