Export DB data in json format

Use pudo / dataset written in python.

Installation

$ pip install --local dataset

Here, by specifying the --local option, the datafreeze command is installed in ~ / .local / bin in the home directory. Please set the PATH appropriately.

Prepare config file config.yaml

common:

  database: "mysql://[email protected]/information_schema"

exports:

  - query: "SELECT * FROM COLLATIONS"
    filename: "collations.json"
    format: json

Execution result

$ datafreeze config.yaml

cat collations.json

[{"COLLATION_NAME": "big5_chinese_ci", "CHARACTER_SET_NAME": "big5", "ID": 1, "IS_DEFAULT": "Yes", ...

More details

Programming interface

You can also use it by importing it as a library.

import dataset

db = dataset.connect('mysql://[email protected]/information_schema')

for table in db.tables:
    result = db[table].all()
    dataset.freeze(result, format='json', filename='{0}.json'.format(table))

See also There is an official document with cute characters. dataset: databases for lazy people

Internally, SQLAlchemy is used.

I also wrote an article about the dataset itself. Python-Super easy OR mapper dataset for lazy people-Qiita

Recommended Posts

Export DB data in json format
Easily format JSON in Python
Write data in HDF format
Handle NetCDF format data in Python
Merge JSON format data with Ansible
Export the contents acquired by Twitter Streaming API in JSON format
[Django] Import and export DB tables in Excel or CSV format
Data input / output in Python (CSV, JSON)
Export Amazon RDS tables in CSV format
Export CASTable data
format in python
Try to extract specific data from JSON format data in object storage Cloudian/S3
[Introduction to Python] How to handle JSON format data
Convert json format data to txt (using yolo)
Sampling in imbalanced data
Handling json in python
Image format in Python
Output log in JSON format with Python standard logging
Returns json in Pyramid
Convert / return class object to JSON format in Python
Try writing JSON format data to object storage Cloudian/S3
Eliminate garbled Japanese characters in JSON data acquired by API.
Extract classification information etc. from genbank data in xml format
[Python] Use JSON format data as a dictionary type object
Handle Ambient data in Python
Export 3D data from QGIS
Data handling 3 (development) About data format
Data Manipulation in Python-Try Pandas_plyr
Display UTM-30LX data in Python
Display Japanese in JSON file
Format json with Vim (with python)
How to return the data contained in django model in json format and map it on leaflet
Read json data with python
[Python / Django] Create a web API that responds in JSON format
Best practice for logging in JSON format on AWS Lambda / Python