title: How to serialize object to json with custom fields in python
body: <p>I have a class</p>
  
  <pre><code>class Person(object):
      def __init__(self,age,name):
          self.person_age = age
          self.person_name = name
  </code></pre>
  
  <p>And i want to serialize object to json. I can do so:</p>
  
  <pre><code>person = Person(20,'Piter')
  person.__dict__
  </code></pre>
  
  <p>But such an approach will return it:</p>
  
  <pre><code>{'person_age':20,person_name:'Piter'}
  </code></pre>
  
  <p>I want serialize my object to json with my own fields. Instead of 'person_age' - 'age'. Instead of 'person_name' - 'name':</p>
  
  <pre><code>{'age':20,name:'Piter'}
  </code></pre>
  
  <p>How can this be done if the class has many fields?</p>