Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9304031
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T23:37:06+00:00 2026-06-18T23:37:06+00:00

I have a sqlalchemy result labels = session.query( LabelsData, LabelsData.id, LabelsData.name, LabelsData.color ).filter(LabelsData.deleted==False).all() And

  • 0

I have a sqlalchemy result

labels = session.query(
         LabelsData, 
         LabelsData.id, 
         LabelsData.name, 
         LabelsData.color
         ).filter(LabelsData.deleted==False).all()

And I want convert this result to JSON, but how I can do it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T23:37:07+00:00Added an answer on June 18, 2026 at 11:37 pm

    It looks like your LabelsData object is a SQLAlchemy model. You need to serialize it before dumping it to JSON. Here’s a short example that extracts all the columns from your LabelsData object and converts the results of your query to JSON:

    from json import dumps
    from sqlalchemy.orm import class_mapper
    
    def serialize(model):
      """Transforms a model into a dictionary which can be dumped to JSON."""
      # first we get the names of all the columns on your model
      columns = [c.key for c in class_mapper(model.__class__).columns]
      # then we return their values in a dict
      return dict((c, getattr(model, c)) for c in columns)
    
    # we can then use this for your particular example
    serialized_labels = [
      serialize(label)
      for label in session.query(LabelsData).filter(LabelsData.deleted == False)
    ]
    your_json = dumps(serialized_labels)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The Sqlalchemy result can have 0 to many records. Result is: record = meta.Session.query(model.EmpsTable).filter(model.EmpsTable
I have recently started using SQLALCHEMY to query a my-sql database. I want to
I have some sqlalchemy query: >>> items = ( Company.query .add_column(Address.city) .join(Company.address) .filter(and_( ...some
I'm using SQLalchemy for a Python project, and I want to have a tidy
I am creating SQLAlchemy class that represents user credentials. I want to have field
I have an sqlalchemy query that returns a tuple. I pass this tuple to
I have the following command that's kind of working as expected: DBSession.query(Users).filter(or_(Users.first_name.contains(search_term),Users.last_name.contains(search_term))).all() I searches
If I have an sqlalchemy-mapped instance. Can I get an underlying dynamic query object
I have a SQL query that I execute like this with an SQLAlchemy engine:
I have a rather complex base class for some sqlalchemy models and I want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.