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
- domonic.JSON.flatten(b, delim='__')[source]
# i.e. input = map( lambda x: JSON.flatten( x, “__” ), input )