Here is described a powerful and easy way to export your project blocks data to a JSON file using the Python block built-in capabilities as a Output block.
You simply need to have a Python block with a 1 line script to instruct Omniscope to transform the input block data into a JSON file and output it to your disk.
Here is described a powerful and easy way to export your project blocks data to a JSON file using the Python block built-in capabilities as a Output block.
You simply need to have a Python block with a 1 line script to instruct Omniscope to transform the input block data into a JSON file and output it to your disk.
I have created a project to demonstrate it : https://omniscope.me/Forums/Export+data+to+JSON+file.iox/
We can use the Python to_json method to write data in JSON format and use the orient parameter to control the data structure.
Say that your block data is a table made of 2 columns and 2 rows:
A) Writing using 'records' formatted JSON.
input_data.to_json('/home/youruser/omniscope-server/files/myFile.json', orient='records')
output:
B) Writing using 'index' formatted JSON
input_data.to_json('/home/youruser/omniscope-server/files/myFile.json', orient='index')
output:
C) Writing using 'columns' formatted JSON
input_data.to_json('/home/youruser/omniscope-server/files/myFile.json', orient='columns')
output:
D) Writing using 'values' formatted JSON
input_data.to_json('/home/youruser/omniscope-server/files/myFile.json', orient='values')
output:
E) Writing with Table Schema
input_data.to_json('/home/youruser/omniscope-server/files/myFile.json', orient='table')
output:
'{"schema": {"fields": [{"name": "index", "type": "string"},
{"name": "col 1", "type": "string"},
{"name": "col 2", "type": "string"}],
"primaryKey": "index",
"pandas_version": "0.20.0"},
"data": [{"index": "row 1", "col 1": "a", "col 2": "b"},
{"index": "row 2", "col 1": "c", "col 2": "d"}]}'
0 Votes
0 Comments
Login or Sign up to post a comment