N
N
Neonoviiwolf2018-04-16 09:35:52
Flask
Neonoviiwolf, 2018-04-16 09:35:52

Convert data from db to json in python?

Good
Is there a library to convert strings from the database to json format, otherwise I haven’t figured out how to collect it with handles yet, the output should be like this, the column name and the string value5ad4444532dcc230989133.jpeg

Answer the question

In order to leave comments, you need to log in

4 answer(s)
M
Melkij, 2018-04-16
@Neonoviiwolf

select json_agg(tablename) from tablename;
Everything. Get json array.

P
planc, 2018-04-16
@planc

https://marshmallow.readthedocs.io/en/latest/
https://flask-marshmallow.readthedocs.io/en/latest/

M
Maxim Beach, 2018-04-16
@Zuzik3500

json.loads?

A
Alexander, 2018-04-16
@NeiroNx

I think something like this:

connecror.exec("SELECT * FROM table")
json.dumps(connector.fetchall())

fetchall() - will return an iterable array of strings, where each string is an associative array - which is a ready structure for the dumps() function.
You only need to configure so that there is no duplication of names by their serial numbers - but this is already setting up the connector and connecting to the database.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question