🤖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

    Scheduled Pinned Locked Moved Micropython
    1 Posts 1 Posters 1.8k Views
    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 Offline
      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

      Hello! It looks like you're interested in this conversation, but you don't have an account yet.

      Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

      With your input, this post could be even better 💗

      Register Login
      • First post
        Last post