Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2016-10-05
3
Medium Priority
?
130 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 2000 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

Flask is a microframework for Python based on Werkzeug and Jinja 2. This requires you to have a good understanding of Python 2.7. Lets install Flask! To install Flask you can use a python repository for libraries tool called pip. Download this f…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
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…

704 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