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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T10:29:24+00:00 2026-05-18T10:29:24+00:00

I use this code to define my class in GAE Python: class Pair(db.Model): find

  • 0

I use this code to define my class in GAE Python:

class Pair(db.Model):
    find = db.StringProperty()
    replace = db.StringProperty()
    rule = db.StringProperty()
    tags = db.StringListProperty()
    created = db.DateTimeProperty()
    updated = db.DateTimeProperty(auto_now=True)

Then I use this code to serialize objects of that class with simplejson:

class PairEncoder(json.JSONEncoder):
    def default(self, obj):
        if isinstance(obj, Pair):
            return [str(obj.created), str(obj.updated), obj.find, obj.replace, obj.tags, obj.rule]

Finally I use this code to output the result as the response:

pairsquery = GqlQuery("SELECT * FROM Pair")
        pairs = pairsquery.fetch(1000)
        pairsList = []
        for pair in pairs:
            pairsList.append(json.dumps(pair, cls=PairEncoder))
        serialized = json.dumps({
                                    'pairs': pairsList,
                                    'count': pairsquery.count()
                                    })

        self.response.out.write(serialized)

Here is a sample result I get:

{"count": 2, "pairs": ["[\"2010-12-06 12:32:48.140000\", \"2010-12-06 12:32:48.140000\", \"random string\", \"replacement\", [\"ort\", \"common\", \"movies\"], \"remove\"]", "[\"2010-12-06 12:37:07.765000\", \"2010-12-06 12:37:07.765000\", \"random string\", \"replacement\", [\"ort\", \"common\", \"movies\"], \"remove\"]"]}

All seems to be fine, except one thing – I need the fields in the response to have names from the class Pair, so there won’t be just values but the names of the corresponding fields too. How can I do that?

  • 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-18T10:29:24+00:00Added an answer on May 18, 2026 at 10:29 am
    class PairEncoder(json.JSONEncoder):
        def default(self, obj):
            if isinstance(obj, Pair):
                return {"created": str(obj.created), "updated:": str(obj.updated), "find": obj.find, "replace": obj.replace, "tags": obj.tags, "rule": obj.rule}
            return json.JSONEncoder.default(self, obj)
    

    But you are ‘double encoding’ here – i.e. encoding the pairs, adding that string to an object and encoding that too. If you ‘double decode’ on the other end it should work – but it’s not the ‘proper’ way to do things.

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

Sidebar

Related Questions

I want to use a temp directory that will be unique to this build.
(please excuse that I didn't use aliases). I would like my query output to
My question is about memory use and objects in actionscript 2. If I have
I need to develop a file indexing application in python and wanted to know
Let say I have the following desire, to simplify the IConvertible's to allow me
I am using a 3rd-party rotator object, which is providing a smooth, random rotation
I'm trying to write test harness for part of my Android mapping application. I
I have a script that appends some rows to a table. One of the
I have a new web app that is packaged as a WAR as part
We manage a site for a medical charity. They have a number of links

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.