While trying to use json.dumps in blaze error occurs saying TypeError: object is not JSON serializable.
data = Data("employee.json")
json.dumps(data)
While trying to use json.dumps in blaze error occurs saying TypeError: object is not JSON serializable.
data = Data("employee.json")
json.dumps(data)
You can't directly convert it to JSON.
Alternate way is as follows :
fields = [] # Create an empty list to hold the field names
for fieldName in data.fields: # Iterate the field names
fields.append(fieldName) # Add to the list
result = []
for row in data: # Iterate each row
currentRow = {}
count = 0
for value in row:
currentRow[fields[count]] = value # Add each value with corresponding key from fields
count = count + 1
result.append(currentRow)
print(json.dumps(result))
Because it's a Blaze Data object. Objects with their own functions and objects, you cannot fully encode to json. Read: How to make a class JSON serializable
If you just want to see variable information use pprint
function.
If you want an interactive view of your JSON file, just evaluate its name. You'll get the equivalent of print data.__repr__()
from blaze import Data
from blaze.utils import example
data = Data(example('accounts.json'))
data
# amount name
# 0 100 Alice
# 1 -200 Bob
# 2 300 Charlie
# 3 400 Dennis
# 4 -500 Edith