Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
json
#1
Can anyone please guide with this 



- JSON for hospital information

Take the list of information below and create a JSON structure that describes the same concept: a list of health systems, the hospitals in that system, and the attributes associated with each hospital.
System    Hospital    City        Beds
BJC       BJH         St. Louis   1432
BJC       MOBap       Creve Coeur 1107
SSM       SLUH        St. Louis   965
Mercy     Mercy STL   Creve Coeur 983
In [ ]:

# Use this name and put your JSON version of the above table here...

hospitals = """
"""





Reply
#2

  1. a hospital is a dictionary with at least a 'name' key plus various other key/value pairs
  2. a health system is a dictionary with a 'name' key and a 'hospitals' key whose value is a list of hospitals
  3. the top object is a list of health systems

Unless noted otherwise, code in my posts should be understood as "coding suggestions", and its use may require more neurones than the two necessary for Ctrl-C/Ctrl-V.
Your one-stop place for all your GIMP needs: gimp-forum.net
Reply
#3
I have done this quote can someone please guide me how to correct it . I am getting errors at the end .


import json
#a hospital is a dictionary with at least a 'name' key plus various other key/value pairs
#a health system is a dictionary with a 'name' key and a 'hospitals' key whose value is a list of hospitals 
#the top object is a list of health systems
hospitals= {}
hospitals ['BJC'] ={
   'hospitals'   :'BJC',
   'name'        :'BJH',
    'city'        :'St.Louis ',
    'Beds'       :1432}
hospitals ['BJC'] ={
   'hospitals'   :'BJC',
  'name'        :' MOBap ',
   'city'        :'Creve Coeur ',
   'Beds'       :110}
hospitals ['SSM'] ={
   'hospitals'   :'SSM',
   'name'        :'SLUH   ',
    'city'        :'St. Louis  ',
    'Beds'       :965


type(hospitals)    
json.dumps(hospital)
Reply
#4
You dont have a closing paren for the last one. You also have 2 entries with the same key.
Recommended Tutorials:
Reply
#5
Thanks for the replies  .Still having issues  . Please guide me through it
import json
#a hospital is a dictionary with at least a 'name' key plus various other key/value pairs
#a health system is a dictionary with a 'name' key and a 'hospitals' key whose value is a list of hospitals 
#the top object is a list of health systems
hospitals= {}
hospitals ['BJH'] ={
   'hospitals'   :'BJH',
   'system'        :'BJC',
    'city'        :'St.Louis ',
    'Beds'       :1432}
hospitals ['MOBap'] ={
  'hospitals'   :'MOBap',
'system'        :' BJC ',
 'city'        :'Creve Coeur ',
 'Beds'       :110}
hospitals ['SLUH'] ={
  'hospitals'   :'SLUH',
  'system'        :'SSM   ',
   'city'        :'St. Louis  ',
  'Beds'       :965}
hospitals ['Mercy STL'] =[{
   'hospitals'   :'Mercy STL',
   'system'        :'Mercy',
    'city'        :'Creve Coeur ',
    'Beds'       : 983}                    

print(hospitals)
 The error is
Error:
``` File "<ipython-input-40-a21e01f55280>", line 28    print(hospitals)        ^ SyntaxError: invalid syntax ```
Reply
#6
hospitals ['Mercy STL'] =[{ # Remove [
Reply
#7
Why not build it like so:
hospitals = {
    'BJH': {
        'hospitals': 'BJH',
        'system': 'BJC',
        'city': 'St.Louis ',
        'Beds': 1432
    },
    'MOBap': {
        'hospitals': 'MOBap',
        'system': ' BJC ',
        'city': 'Creve Coeur ',
        'Beds': 110
    },
    'SLUH': {
        'hospitals': 'SLUH',
        'system': 'SSM   ',
        'city': 'St. Louis  ',
        'Beds': 965
    },
    'Mercy STL': {
        'hospitals': 'Mercy STL',
        'system': 'Mercy',
        'city': 'Creve Coeur ',
        'Beds': 983
    }
}

print('hospitals: {}'.format(hospitals))

print('\nhospitals - SLUH - system: {}'.format(hospitals['SLUH']['system']))
output:
Output:
hospitals: {'SLUH': {'Beds': 965, 'system': 'SSM   ', 'city': 'St. Louis  ', 'hospitals': 'SLUH'}, 'Mercy STL': {'Beds': 983, 'system': 'Mercy', 'city': 'Creve Coeur ', 'hospitals': 'Mercy STL'}, 'MOBap': {'Beds': 110, 'system': ' BJC ', 'city': 'Creve Coeur ', 'hospitals': 'MOBap'}, 'BJH': {'Beds': 1432, 'system': 'BJC', 'city': 'St.Louis ', 'hospitals': 'BJH'}} hospitals - SLUH - system: SSM  
Reply
#8
Thanks everyone .This forum is so helpful .
Reply


Forum Jump:

User Panel Messages

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