Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

212
Visualizações
How do I print a .json file in python

I was wondering if anyone knows how to print a .json file in python using the same formatting as if I was running it from JavaScript. I’m using it for api usage and the output is .json but when I print it I get this: link to image

However the api documentation has this: another image

(The images show different sections of it)

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

I guess you mean how to print a json formatted, if so, you could do

import json
with open('yourfile.json', 'r') as handle:
    parsed = json.load(handle)
print(json.dumps(parsed, indent=4, sort_keys=True))

If you want to do it like Javascript there's a way

var str = JSON.stringify(YourJsonObject, null, 4);

Or another way

import json 
     
# Opening JSON file 
f = open('yourjsonfile.json',) 
     
# returns JSON object as  
# a dictionary 
data = json.load(f) 
     
print(json.dumps(data, indent = 4)
     
# Closing file 
f.close() 

Also

import json

print json.dumps(jsonstring, indent=4)
about 4 years ago · Juan Pablo Isaza Relatório

0

This should do the trick:

import json
print(json.dumps(my_input, sort_keys=True, indent=4))

See https://docs.python.org/3/library/json.html

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda