🤖Have you ever tried Chat.M5Stack.com before asking??😎
    M5Stack Community
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    Trouble Passing Decoded JSON to Variable

    Micropython
    1
    1
    519
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • S
      shubhh1989
      last edited by

      I'm having some trouble with passing a decoded JSON object to a variable in my project. Here's a simplified version of my code:

      import json

      json_string = '{"name": "John", "age": 30, "city": "New York"}'
      decoded_json = json.loads(json_string)

      Trying to pass decoded JSON to a variable

      name = decoded_json['name']
      age = decoded_json['age']
      city = decoded_json['city']

      print(name, age, city)

      When I run this code, it works fine and prints the expected values. However, in my actual project, I'm encountering issues where the variables don't seem to get assigned correctly, and I'm getting errors like TypeError or KeyError.

      Can anyone help me understand why this might be happening and suggest ways to troubleshoot or fix the issue? Are there any common pitfalls when working with JSON in Python that I should be aware of?

      1 Reply Last reply Reply Quote 0
      • kurikoK kuriko moved this topic from News and Blog posts on
      • First post
        Last post