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

  • Home
  • SEARCH
  • 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 5968555
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:06:24+00:00 2026-05-22T20:06:24+00:00

I have a simple code to fetch users from db using sqlalchemy and return

  • 0

I have a simple code to fetch users from db using sqlalchemy and return them as json. My problem is how to format the output to get something like this:

{"results": [{"id":1, "username":"john"},{"id":2,"username":"doe"}]}

my code outputs an error which I cant seem to fix being a newbie in python:

d = []

for user in Users.query.all():
    v = {}
    for columnName in Users.__table__.columns.keys():
        v[columnName] = getattr( user, columnName )

    d.append( v )

return jsonify( d )

The code says:

ValueError: dictionary update sequence element #0 has length 11; 2 is required

Thanks.

  • 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-05-22T20:06:24+00:00Added an answer on May 22, 2026 at 8:06 pm

    Ah, now that your code has been pasted, I can see that the fundamental problem is indeed coming from jsonify. The below workaround should be satisfactory.

    >>> import json
    >>> json.dumps({"results": [{"id":1, "username":"john"},{"id":2,"username":"doe"}]})
    '{"results": [{"username": "john", "id": 1}, {"username": "doe", "id": 2}]}'
    

    Replace jsonify with json.dumps, and let me know if that doesn’t fix the problem.

    But if you’d prefer to use flask.jsonify, then you should take a look at the flask documentation. The argument to jsonify should be the same as the argument to any dict constructor — i.e. a dict or an iterable of tuples. So that’s the problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple 3D cube that I can rotate using the following code:
I have some very simple code to generate an assembly and invoke a method
I have a simple piece of code: public string GenerateRandomString() { string randomString =
I have a simple application with the following code: FileInfo[] files = (new DirectoryInfo(initialDirectory)).GetFiles();
I have a simple function that I want to call in the code behind
I have to code a simple control in .Net that draws geometry that looks
I have a fairly simple const struct in some C code that simply holds
I have some code I've written in PHP for consuming our simple webservice, which
There is probably is simple fix for this but I currently have code similar
Currently, I have some basic code to play a simple tone whenever a button

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.