Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
json load problem
#7
I never should have thrown that example at you without modification,
I just grabbed it from a project.

Here's a simpler example:
import json


def make_json():
   init_data = {
       'rotor1_info': {
           'name': 'rotor1',
           'cipher': 'EKMFLGDQVZNTOWYHXUSPAIBRCJ',
           'notches': ['R'],
       }
   }

   with open('simple.json', 'w') as f:
       json.dump(init_data, f)


def test_read():
   mydata = {}
   with open('simple.json') as f:
       mydata = json.load(f)

   for key, value in mydata.items():
       print('key: {}, Value: {}'.format(key, value))


if __name__ == '__main__':
   make_json()
   test_read()
running get these results:
Output:
key: rotor1_info, Value: {'name': 'rotor1', 'cipher': 'EKMFLGDQVZNTOWYHXUSPAIBRCJ', 'notches': ['R']}
Reply


Messages In This Thread
json load problem - by mepyyeti - Dec-27-2017, 06:10 AM
RE: json load problem - by buran - Dec-27-2017, 07:32 AM
RE: json load problem - by mepyyeti - Dec-27-2017, 07:13 PM
RE: json load problem - by Larz60+ - Dec-27-2017, 08:32 PM
RE: json load problem - by mepyyeti - Dec-27-2017, 09:44 PM
RE: json load problem - by Larz60+ - Dec-28-2017, 02:05 AM
RE: json load problem - by Larz60+ - Dec-28-2017, 02:15 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  JSON Dump and JSON Load foxholenoob 8 1,209 Oct-12-2023, 07:21 AM
Last Post: foxholenoob
  Problem with nested JSON Kalet 7 2,854 Dec-09-2021, 11:13 PM
Last Post: Gribouillis
  Problem With Database Calls and Load Timbo03 1 2,151 Nov-21-2021, 10:48 AM
Last Post: Timbo03
  Problem with Json Array kwekey 2 1,719 Aug-02-2021, 05:11 PM
Last Post: kwekey
  Problem to parse a json enigma619 3 2,432 Dec-04-2020, 08:16 AM
Last Post: enigma619
  Python - help with getting JSON from one DB and load to another DB qIekm 4 3,349 Apr-16-2020, 07:07 AM
Last Post: qIekm
  json problem enigma619 9 3,806 Dec-19-2019, 08:29 AM
Last Post: enigma619
  problem with mapnik in anaconda python 2: from _mapnik import * ImportError: DLL load parsley 0 1,941 Dec-11-2019, 07:50 AM
Last Post: parsley
  Output to a json file problem Netcode 3 3,800 Nov-22-2019, 01:44 AM
Last Post: Skaperen
  Load JSON file data into mongodb using pymongo klllmmm 1 11,918 Jun-28-2019, 12:47 AM
Last Post: klllmmm

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020