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 7901083
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T09:07:51+00:00 2026-06-03T09:07:51+00:00

I have a json field in my database which is like jsonfield = {‘username’:’chingo’,’reputation’:’5′}

  • 0

I have a json field in my database which is like

jsonfield = {'username':'chingo','reputation':'5'}

how can i write a query so that i can find if a user name exists. something like

username = 'chingo'
query = User.objects.get(jsonfield['username']=username)

I know the above query is a wrong but I wanted to know if there is a way to access 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-03T09:07:52+00:00Added an answer on June 3, 2026 at 9:07 am

    This usage is somewhat anti-pattern. Also, its implementation is not going to have regular performance, and perhaps is error-prone.
    Normally don’t use jsonfield when you need to look up through fields. Use the way the RDBMS provides or MongoDB(which internally operates on faster BSON), as Daniel pointed out.

    Due to the deterministic of JSON format,
    you could achieve it by using contains (regex has issue when dealing w/ multiple '\' and even slower), I don’t think it’s good to use username in this way, so use name instead:

    def make_cond(name, value):
        from django.utils import simplejson 
        cond = simplejson.dumps({name:value})[1:-1] # remove '{' and '}'
        return ' ' + cond # avoid '\"'
    
    User.objects.get(jsonfield__contains=make_cond(name, value))
    

    It works as long as

    • the jsonfield using the same dump utility (the simplejson here)
    • name and value are not too special (I don’t know any egde-case so far, maybe someone could point it out)
    • your jsonfield data is not corrupt (unlikely though)

    Actually I’m working on a editable jsonfield and thinking about whether to support such operations. The negative proof is as said above, it feels like some black-magic, well.

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

Sidebar

Related Questions

I have a form field which requires a json object as its value when
We have a JSON response which can contain null values (e.g. { myValue: null
I have a string in database (mysql) which is like: {StateId:73,CallTime:\/Date(1336365498912+0500)\/,CallId:1336365489.14157,Target:agi://127.0.0.1}},Profile:{$type:DataWriter.DbProfile, DataWriterObjects,Name:DataService,Provider:mssql,ConnectionString:Data Source=localhost\\mydb; Database=mydb;
I have a table contacts that has a field arrayOfMembers (JSON format) and a
I have a json feed from this URL which contains 20 fields and I
I have JSON text that looks like this: { ok: true, totalPages: 256, arReports:
i have json data like this {GetStudentDetails: {TotalCount:5, RootResults:[ {city:West Chester,country:USA,state:PA ,student_id:100}, {city:Philly,country:USA,state:PA,student_id:101}, {city:Buffalo,country:USA,state:NY,student_id:102},
I have a dictionary in JSON form, like this: $user = { name: Mary
I have a json object in my JavaScript file containing qs: {} which when
I'm designing a contact manager/address book-like application but can't settle on the database design.

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.