Solved

python - JSON needs to be converted to a python dictionary (has some nested json)

Posted on 2016-10-05
3
96 Views
Last Modified: 2016-10-05
I need a way to convert a string like this:

{
    "event": {
                      "event_type":"method_Name",
                      "event_time":"1475692166",
                      "event_hash":"1234",
                      "event_metadata": {
                                                          "related_firstName":null,
                                                          "reported_secondName":"1234",
                                                          "reported_for_ID":null,
                                                          "event_message":null
                                                    }
                }
 }

into a python dictionary and I need to deal with the nested JSON array's as well.
0
Comment
Question by:alexmac05
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 16

Accepted Solution

by:
Walter Ritzel earned 500 total points
ID: 41830919
[code]
import json
new_dict = json.loads("{'1':'text'}")
print(new_dict)
[\code]
0
 

Author Comment

by:alexmac05
ID: 41830940
strData = '''
{"event": {"event_type":"method_Name","event_time":"1475692166","event_hash":"1234","event_metadata": {"related_firstName":null,"reported_secondName":"1234","reported_for_ID":null,
"event_message":null}}}'''


#print(strData)

new_dict = json.loads(strData)
print(type(new_dict))
print(new_dict['event']['event_metadata']['reported_secondName'])
0
 

Author Closing Comment

by:alexmac05
ID: 41830941
This is the code with Walter's answer


strData = '''
{"event": {"event_type":"method_Name","event_time":"1475692166","event_hash":"1234","event_metadata": {"related_firstName":null,"reported_secondName":"1234","reported_for_ID":null,
"event_message":null}}}'''


#print(strData)

new_dict = json.loads(strData)
print(type(new_dict))
print(new_dict['event']['event_metadata']['reported_secondName'])
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article discusses how to create an extensible mechanism for linked drop downs.
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question