How do I convert an object to JSON?
I even found some codes on the internet that even worked, but my object has some fields that are other objects and then the conversion did not reach the last level.
Example:
class Pessoa(object):
codigo = 0
nome = ''
endereco = Endereco()
class Endereco(object):
codigo = 0
logradouro = ''
bairro = ''
cidade = Cidade()
class Cidade(object):
codigo = 0
nome = ''
uf = ''
These are my objects, but by doing the conversion I found, the JSON result comes only with the values contained in Person in Address , then City from outside of JSON:
{
'codigo': 1,
'nome': 'Oliveira',
'endereco': {
'codigo': 5,
'logradouro': 'Rua A',
'bairro': 'Campos'
}
}
That is, I believe the code did not go through all levels.
I'm using pyMongo and I saw that you have a bson library that has some conversions but I did not know how to use it or else it does not do what I need.