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

371
Visualizações
How to get values from this json in python?

I am currently working in python and getting some json response from API. but after trying my best to fetch data from json, I am always getting this error, TypeError: string indices must be integers, not str here is my JSON file that I received,

{
  "from": 1,
  "to": 10,
  "currentPage": 1,
  "total": 72,
  "totalPages": 8,
  "queryTime": "0.023",
  "totalTime": "0.059",
  "partial": false,
  "canonicalUrl": "/v1/products(categoryPath.name=All Flat-Panel TVs)?show=sku,name,salePrice&format=json&apiKey=APIKEY",
  "products": [{
    "sku": 3813048,
    "name": "Samsung - 32\" Class (31-1/2\" Diag.) - LED - 1080p - HDTV - Black",
    "salePrice": 229.99
  }, {
    "sku": 4340402,
    "name": "Samsung - 43\" Class (42.5\" Diag.) - LED - 1080p - Smart - HDTV - Black",
    "salePrice": 429.99
  }, {
    "sku": 4380083,
    "name": "Samsung - 32\" Class (31.5\" Diag.) - LED - 1080p - Smart - HDTV - Silver",
    "salePrice": 299.99
  }, {
    "sku": 4405201,
    "name": "Samsung - 50\" Class (49.5\" Diag.) - LED - 1080p - Smart - HDTV - Black",
    "salePrice": 499.99
  }, {
    "sku": 4559300,
    "name": "VIZIO - 39\" Class (38.5\" Diag.) - LED - 720p - Smart - HDTV - Black",
    "salePrice": 269.99
  }, {
    "sku": 4562031,
    "name": "Samsung - 58\" Class (57.5\" Diag.) - LED - 1080p - Smart - HDTV - Black",
    "salePrice": 649.99
  }, {
    "sku": 4569901,
    "name": "LG - 24\" Class (23.6\" Diag.) - LED - 720p - HDTV - Black",
    "salePrice": 84.99
  }, {
    "sku": 4613600,
    "name": "Samsung - 32\" Class (31.5\" Diag.) - LED - 720p - Smart - HDTV - Black",
    "salePrice": 219.99
  }, {
    "sku": 4629257,
    "name": "Samsung - 32\" Class (31.5\" Diag.) - LED - 720p - HDTV - Black",
    "salePrice": 199.99
  }, {
    "sku": 4673800,
    "name": "Insignia™ - 24\" Class (23.6\" Diag.) - LED -720p - Smart - Roku TV - Black",
    "salePrice": 139.99
  }]
}

and I have tried in following ways,

for item in result["products"]:
    print(item["sku"])
    print(item["name"])
    print(item["salePrice"])

and

for item in result:
    print(item["products"]["sku"])
    print(item["products"]["name"])
    print(item["products"]["salePrice"])

Can anyone tell me please where I am wrong? Can you please share some tutorials where I can understand how to decode json properly. thanks in advance

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

You must be missing to parse this json. Parse it first and then do as you are doing.

import json
results = json.loads(results)
for item in results['products']:
    print(item["sku"])
over 4 years ago · Santiago Trujillo 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