Nested result in JSON format
Peewee has a helper called "model_to_dict" which can construct (recursively, if you desire) a dictionary containing model data, which can then be serialized as JSON.

http://docs.peewee-orm.com/en/latest/peewee/playhouse.html#model_to_dict Thanks for answer, but I did try use backrefs parameter in model_to_dicts but don't worked for me.

#My models:
```
class TBEstados(BaseModel):
    ativo = IntegerField(null=True)
    nome = CharField()
    uf = CharField(null=True)

    class Meta:
        db_table = 'TBEstados'

class TBCidades(BaseModel):
    ativo = IntegerField(null=True)
    idestado = ForeignKeyField(db_column='idEstado', null=True, rel_model=TBEstados, to_field='id', backrefs=True)
    nome = CharField(null=True)

    class Meta:
        db_table = 'TBCidades
```
#select data 

`data = TBCidades.select().where(TBCidades.idestado == idEstado and TBCidades.ativo == True).dicts()`

#Calling the model_to_dict function

```
def toJSON(obj):
    obj = [model_to_dict(t, backrefs=True) for t in obj]
    return jsonify(obj)
```

#result JSON
```
[
  {
    "ativo": 1, 
    "id": 1, 
    "idestado": 1, 
    "nome": "Acrel\u00e2ndia"
  }
]
``` You want `recurse=True` if the foreign key is on the model you're attempting to serialize. Thanks, but I did try use recurse=True and don't work.
```

def toJSON(obj):
    obj = [model_to_dict(t, recurse=True) for t in obj]
    return jsonify(obj)
```

I ask me if haven't problem in my model.
Please,

How can I use a query with Peewee to return a JSON format with Nested objects?
Example:

```
[
  {
    "active": 1, 
    "id": 1, 
    "name": "Los Angeles",
    "idState": 2,
    "TBState": {
         "id": 2,
         "name": "California"                
     }
  }
]
```
I can it using SqlAlchemy using relationship by model but in Peewee I don't know as make.
Thanks!