Sie sind auf Seite 1von 74

MODULE-2

WEB Services Protocols


Application
Programmable Interface
Lesson 1
Introduction to Web Services and REST API
Web Services (User)

http://www.XYZ.com/home/full-course-catalog

Introduction to Networking

Introduction to Python

Introduction to Web Services


Web Services (Node)

XML
eXtensible Markup Language

JSON
Java Script Oriented Notation

WSDL
Web Services Description Language

SOAP
Simple Object Access Protocol

REST
REpresentational State Transfer
Web Services (Transport)

XML JSON WSDL REST SOAP

SSH HTTP
REST Overview

Sending Strings Configuration


File
Receiving Strings

SSH)

Source
CLI Switch/
Router

Post , Modify, Delete


Tree (MIM)
Get

HTTP(s)
SSH

Source REST Appliance


Management Information Model

Post , Get, Modify, Delete

HTTP://10.1.1.1/root/parent1/child2/object3

root

parent1 parent2

child1 child2 child3 child4

object1 object2 object3 object4 object5 object6 object7 object8


Management Information Model

HTTP://10.1.1.1/root/parent1/child2/object3

root

parent1 parent2

child1 child2 child3 child4

object1 object2 object3 object4 object5 object6 object7 object8


Management Information Model

HTTP://10.1.1.1/root/parent1/child2/object3

root

parent1 parent2

child1 child2 child3 child4

object1 object2 object3 object4 object5 object6 object7 object8


What is REST?

HTTP://10.1.1.1/root/parent1/child2/object3

root

parent1 parent2

child1 child2 child3 child4

object1 object2 object3 object4 object5 object6 object7 object8


What is REST?

HTTP://10.1.1.1/root/parent1/child2/object3

root

parent1 parent2

child1 child2 child3 child4

object1 object2 object3 object4 object5 object6 object7 object8


The MIM Tree

HTTP://10.1.1.1/root/parent1/child2/object3

root

parent1 parent2

child1 child2 child3 child4

object1 object2 object3 object4 object5 object6 object7 object8


The MIM Tree

HTTP://10.1.1.1/api/chassis1/linecard2/port1

api

chassis1 chassis2

linecard1 linecard2 linecard1 linecard2

port1 port2 port1 port2 port1 port2 port1 port2


The MIM Tree

HTTP://10.1.1.1/api/chassis1/linecard2/port1

api

chassis1 chassis2

linecard1 linecard2 linecard1 linecard2

port1 port2 port1 port2 port1 port2 port1 port2


The MIM Tree

HTTP://10.1.1.1/api/chassis1/linecard2/port1

api

chassis1 chassis2

linecard1 linecard2 linecard1 linecard2

port1 port2 port1 port2 port1 port2 port1 port2


The MIM Tree

HTTP://10.1.1.1/api/chassis1/linecard2/port1

api

chassis1 chassis2

linecard1 linecard2 linecard1 linecard2

port1 port2 port1 port2 port1 port2 port1 port2


The MIM Tree

HTTP://10.1.1.1/api/chassis1/linecard2/port1

api

chassis1 chassis2

linecard1 linecard2 linecard1 linecard2

port1 port2 port1 port2 port1 port2 port1 port2


Object Naming

Distinguished Name

dn = api/mo/chassis1/linecard1/port1
Object Naming

Distinguished Name

dn = api/mo/chassis1/linecard1/port1

class = api/class/LineCards
Encoded Documents

Sending Strings Configuration


File
Receiving Strings

SSH)

Source
CLI Switch/
Router

Post , Modify, Delete, Get

{
<?xml version="1.0" encoding=“UTF-8"?> Company: {
Employee:{

Tree (MIM)
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> ‘FirstName’: ’Tanmay’,
<xs:element name="contact"> ‘LastName’ : ‘Patil’,
<xs:complexType> ‘ContactNo’:’1234567890’,
<xs:sequence> ‘Email’: ‘tanmaypatil@xyz.com’,
<xs:element name="name" type="xs:string" /> ‘Address’: {
<xs:element name="company" type="xs:string" /> ‘City’: ‘Banglore’,
<xs:element name="phone" type="xs:int" /> ‘State’: ‘Karnataka’,
</xs:sequence> ‘Zip’ : ‘560212’
</xs:complexType> }
</xs:element> }
</xs:schema> }
}

HTTP(s)
SSH

Source REST Destination


Application
Programmable Interface
Lesson 2
Extensible Markup Language(XML)
and
Java Script Oriented Notation (JSON)
What is XML?

<?xml version="1.0" encoding=“UTF-8"?>

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="contact">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string" />
<xs:element name="company" type="xs:string" />
<xs:element name="phone" type="xs:int" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
What is XML?

<?xml version="1.0" encoding=“UTF-8"?>

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="contact">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string" />
<xs:element name="company" type="xs:string" />
<xs:element name="phone" type="xs:int" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
What is XML?

<?xml version="1.0" encoding=“UTF-8"?>

Tags <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">


<xs:element name="contact">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string" />
<xs:element name="company" type="xs:string" />
<xs:element name="phone" type="xs:int" />
</xs:sequence>
</xs:complexType>
</xs:element>
Tags
</xs:schema>
What is XML?

<?xml version="1.0" encoding=“UTF-8"?>

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
Tags <xs:element name="contact">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string" />
<xs:element name="company" type="xs:string" />
<xs:element name="phone" type="xs:int" />
</xs:sequence>
</xs:complexType>
Tags </xs:element>
</xs:schema>
What is XML?

<?xml version="1.0" encoding=“UTF-8"?>

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="contact">
Tags <xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string" />
<xs:element name="company" type="xs:string" />
<xs:element name="phone" type="xs:int" />
</xs:sequence>
Tags </xs:complexType>
</xs:element>
</xs:schema>
What is XML?

<?xml version="1.0" encoding=“UTF-8"?>

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="contact">
<xs:complexType>
Tags <xs:sequence>
<xs:element name="name" type="xs:string" />
<xs:element name="company" type="xs:string" />
<xs:element name="phone" type="xs:int" />
Tags </xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
What is XML?

<?xml version="1.0" encoding=“UTF-8"?>

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="contact">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string" />
<xs:element name="company" type="xs:string" />
<xs:element name="phone" type="xs:int" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
XML Format

<?xml version="1.0"?>
<Company>
<Employee>
<FirstName>Tanmay</FirstName>
<LastName>Patil</LastName>
<ContactNo>1234567890</ContactNo>
<Email>tanmaypatil@xyz.com</Email>
<Address>
<City>Bangalore</City>
<State>Karnataka</State>
<Zip>560212</Zip>
</Address>
</Employee>
</Company>
XML Format

<?xml version="1.0"?>
<Company>
<Employee>
<FirstName>Tanmay</FirstName>
<LastName>Patil</LastName>
<ContactNo>1234567890</ContactNo>
<Email>tanmaypatil@xyz.com</Email>
<Address>
<City>Bangalore</City>
<State>Karnataka</State>
<Zip>560212</Zip>
</Address>
</Employee>
</Company>
XML Format

<?xml version="1.0"?>
<Company>
<Employee>
<FirstName>Tanmay</FirstName>
<LastName>Patil</LastName>
<ContactNo>1234567890</ContactNo>
<Email>tanmaypatil@xyz.com</Email>
<Address>
<City>Bangalore</City>
<State>Karnataka</State>
<Zip>560212</Zip>
</Address>
</Employee>
</Company>
XML Format

<?xml version="1.0"?>
<Company>
<Employee>
<FirstName>Tanmay</FirstName>
<LastName>Patil</LastName>
<ContactNo>1234567890</ContactNo>
<Email>tanmaypatil@xyz.com</Email>
<Address>
<City>Bangalore</City>
<State>Karnataka</State>
<Zip>560212</Zip>
</Address>
</Employee>
</Company>
XML Format

<?xml version="1.0"?>
<Company>
<Employee>
<FirstName>Tanmay</FirstName>
<LastName>Patil</LastName>
<ContactNo>1234567890</ContactNo>
<Email>tanmaypatil@xyz.com</Email>
<Address>
<City>Bangalore</City>
<State>Karnataka</State>
<Zip>560212</Zip>
</Address>
</Employee>
</Company>
XML Format

<?xml version="1.0"?>
<Company>
<Employee>
<FirstName>Tanmay</FirstName>
<LastName>Patil</LastName>
<ContactNo>1234567890</ContactNo>
<Email>tanmaypatil@xyz.com</Email>
<Address>
<City>Bangalore</City>
<State>Karnataka</State>
<Zip>560212</Zip>
</Address>
</Employee>
</Company>
What is JSON?

{Company: {Employee:{‘FirstName’: ’Tanmay’,‘LastName’ :


‘Patil’,‘ContactNo’:’1234567890’,‘Email’: ‘tanmaypatil@xyz.com’,’Address’:‘City’:
‘Banglore’,‘State’: ‘Karnataka’,‘Zip’ : ‘560212’}}}
Formatted JSON

{
Company: {
Employee:{
‘FirstName’: ’Tanmay’,
‘LastName’ : ‘Patil’,
‘ContactNo’:’1234567890’,
‘Email’: ‘tanmaypatil@xyz.com’,
‘Address’: {
‘City’: ‘Banglore’,
‘State’: ‘Karnataka’,
‘Zip’ : ‘560212’
}
}
}
}
Application
Programmable Interface
Lesson 3
Data Models
Schema Overview

CLIENT A SERVER / DEVICE

B File

C
A
D

F
Schema

B File

C
A
D

F
Schema Overview

B File

POST C
A
D

F
A
Schema Overview is in the
Schema File!

B File

POST C
A
D

F
Schema Overview

B File

POST C
A
D

F
Schema Overview

A
Update
B File

POST C
A A
D

F
Schema Overview

B File

POST C
G A
D

F
Schema Overview

B File

REJECT C
G A
D

F
Data Models
XML-Schema
XML Schema
XML
POST <xs:complexType name="computePsuPolicy" mixed="true">
XML
<xs:annotation> SCHEMA
<xs:appinfo>
<moClass value="computePsuPolicy" encrypted="false"/>
<label value="PSU Policy" default="false"/>
<rn value="psu-policy"/>
<access value="admin, pn-equipment, pn-policy"/>
<description value="NO COMMENTS"/>
</xs:appinfo>
<configConfMos
</xs:annotation>
inHierarchical="no">
<inConfigs> <xs:attribute name="redundancy">
<pair <xs:annotation>
key="org-root/psu-policy"> <xs:appinfo>
<moProperty value="computePsuDef:redundancy"/>
<computePsuPolicy
<label value="Redundancy" default="true"/>
descr="" <externAccess value="readWrite"/>
dn="org-root/psu-policy" <description value="NO COMMENTS"/>
policyOwner="local" </xs:appinfo>
redundancy="grid"> </xs:annotation>
</computePsuPolicy> <xs:simpleType>
</pair> <xs:restriction base="xs:string">
<xs:enumeration value="non-redundant"/>
</inConfigs>
<xs:enumeration value="n+1"/>
</configConfMos> <xs:enumeration value="grid"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
GUI
XML Schema

<xs:complexType name="computePsuPolicy" mixed="true">

<xs:annotation>
<xs:appinfo>
<moClass value="computePsuPolicy" encrypted="false"/>
<label value="PSU Policy" default="false"/>
<rn value="psu-policy"/>
<access value="admin, pn-equipment, pn-policy"/>
<description value="NO COMMENTS"/>
</xs:appinfo>
<configConfMos
</xs:annotation>
inHierarchical="no">
<inConfigs>
<xs:attribute name="redundancy">
<pair <xs:annotation>
key="org-root/psu-policy"> <xs:appinfo>
<computePsuPolicy <moProperty value="computePsuDef:redundancy"/>
descr="" <label value="Redundancy" default="true"/>
dn="org-root/psu-policy" <externAccess value="readWrite"/>
policyOwner="local" <description value="NO COMMENTS"/>
</xs:appinfo>
redundancy="grid">
</xs:annotation>
</computePsuPolicy> <xs:simpleType>
</pair> <xs:restriction base="xs:string">
</inConfigs> <xs:enumeration value="non-redundant"/>
</configConfMos> <xs:enumeration value="n+1"/>
<xs:enumeration value="grid"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
XML Schema

<xs:complexType name="computePsuPolicy" mixed="true">

<xs:annotation>
<xs:appinfo>
<moClass value="computePsuPolicy" encrypted="false"/>
<label value="PSU Policy" default="false"/>
<rn value="psu-policy"/>
<access value="admin, pn-equipment, pn-policy"/>
<description value="NO COMMENTS"/>
</xs:appinfo>
<configConfMos
</xs:annotation>
inHierarchical="no">
<inConfigs>
<xs:attribute name="redundancy">
<pair <xs:annotation>
key="org-root/psu-policy"> <xs:appinfo>
<computePsuPolicy <moProperty value="computePsuDef:redundancy"/>
descr="" <label value="Redundancy" default="true"/>
dn="org-root/psu-policy" <externAccess value="readWrite"/>
policyOwner="local" <description value="NO COMMENTS"/>
</xs:appinfo>
redundancy="grid">
</xs:annotation>
</computePsuPolicy> <xs:simpleType>
</pair> <xs:restriction base="xs:string">
</inConfigs> <xs:enumeration value="non-redundant"/>
</configConfMos> <xs:enumeration value="n+1"/>
<xs:enumeration value="grid"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
XML Schema

<xs:complexType name="computePsuPolicy" mixed="true">

<xs:annotation>
<xs:appinfo>
<moClass value="computePsuPolicy" encrypted="false"/>
<label value="PSU Policy" default="false"/>
<rn value="psu-policy"/>
<access value="admin, pn-equipment, pn-policy"/>
<description value="NO COMMENTS"/>
</xs:appinfo>
<configConfMos
</xs:annotation>
inHierarchical="no">
<inConfigs>
<xs:attribute name="redundancy">
<pair <xs:annotation>
key="org-root/psu-policy"> <xs:appinfo>
<computePsuPolicy <moProperty value="computePsuDef:redundancy"/>
descr="" <label value="Redundancy" default="true"/>
dn="org-root/psu-policy" <externAccess value="readWrite"/>
policyOwner="local" <description value="NO COMMENTS"/>
</xs:appinfo>
redundancy="grid">
</xs:annotation>
</computePsuPolicy> <xs:simpleType>
</pair> <xs:restriction base="xs:string">
</inConfigs> <xs:enumeration value="non-redundant"/>
</configConfMos> <xs:enumeration value="n+1"/>
<xs:enumeration value="grid"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
Application
Programmable Interface
Lesson 4
Modifying the Schema
Using CURL

Input
User prompt> curl -d "<configConfMos><inConfigs><pair key=‘org-root/psu-
policy'><computePsuPolicy
redundancy='grid'></computePsuPolicy></pair></inConfigs></configConfMos>"
http://192.168.104.132/nuova

Output

<configConfMos cookie="" response="yes"> <outConfigs> <pair key="org-root/psu-policy">


<computePsuPolicy descr="" dn="org-root/psu-policy" intId="31640" name="PSUPolicy"
policyLevel="0" policyOwner="local" redundancy="grid" status="modified"/> </pair> </outConfigs>
</configConfMos>
Using POSTMAN
Using Python with an API
from ucsmsdk.ucshandle import UcsHandle
from ucsmsdk.mometa.compute.ComputePsuPolicy import ComputePsuPolicy

# Create a connection handle


handle = UcsHandle("172.16.48.135", "cisco", "cisco")

# Login to the server


handle.login()

# Login to the server


powerpol = ComputePsuPolicy(parent_mo_or_dn= "org-root", redundancy = 'grid' )
handle.add_mo(powerpol, modify_present = True)

#commit the configuration and logout


handle.commit()
handle.logout()
<xs:attribute name="redundancy">
<xs:annotation>
<xs:appinfo>
<moProperty value="computePsuDef:redundancy"/>
<label value="Redundancy" default="true"/>
<externAccess value="readWrite"/>
<description value="NO COMMENTS"/>
</xs:appinfo>
</xs:annotation>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="non-redundant"/>
<xs:enumeration value="n+1"/>
<xs:enumeration value="grid"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
Using Python with an API
from ucsmsdk.ucshandle import UcsHandle
from ucsmsdk.mometa.compute.ComputePsuPolicy import ComputePsuPolicy

# Create a connection handle


handle = UcsHandle("172.16.48.135", "cisco", "cisco")

# Login to the server


handle.login()

# Login to the server


powerpol = ComputePsuPolicy(parent_mo_or_dn= "org-root", redundancy = 'grid' )
handle.add_mo(powerpol, modify_present = True)

#commit the configuration and logout


handle.commit()
handle.logout()
<xs:attribute name="redundancy">
<xs:annotation>
<xs:appinfo>
<moProperty value="computePsuDef:redundancy"/>
<label value="Redundancy" default="true"/>
<externAccess value="readWrite"/>
<description value="NO COMMENTS"/>
</xs:appinfo>
</xs:annotation>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="non-redundant"/>
<xs:enumeration value="n+1"/>
<xs:enumeration value="grid"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
Using Python with an API
from ucsmsdk.ucshandle import UcsHandle
from ucsmsdk.mometa.compute.ComputePsuPolicy import ComputePsuPolicy

# Create a connection handle


handle = UcsHandle("172.16.48.135", "cisco", "cisco")

# Login to the server


handle.login()

# Login to the server


powerpol = ComputePsuPolicy(parent_mo_or_dn= "org-root", redundancy = 'grid' )
handle.add_mo(powerpol, modify_present = True)

#commit the configuration and logout


handle.commit()
handle.logout()
<xs:attribute name="redundancy">
<xs:annotation>
<xs:appinfo>
<moProperty value="computePsuDef:redundancy"/>
<label value="Redundancy" default="true"/>
<externAccess value="readWrite"/>
<description value="NO COMMENTS"/>
</xs:appinfo>
</xs:annotation>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="non-redundant"/>
<xs:enumeration value="n+1"/>
<xs:enumeration value="grid"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
Using Python with an API
from ucsmsdk.ucshandle import UcsHandle
from ucsmsdk.mometa.compute.ComputePsuPolicy import ComputePsuPolicy

# Create a connection handle


handle = UcsHandle("172.16.48.135", "cisco", "cisco")

# Login to the server


handle.login()

# Login to the server


powerpol = ComputePsuPolicy(parent_mo_or_dn= "org-root", redundancy = 'grid' )
handle.add_mo(powerpol, modify_present = True)

#commit the configuration and logout


handle.commit()
handle.logout()
<xs:attribute name="redundancy">
<xs:annotation>
<xs:appinfo>
<moProperty value="computePsuDef:redundancy"/>
<label value="Redundancy" default="true"/>
<externAccess value="readWrite"/>
<description value="NO COMMENTS"/>
</xs:appinfo>
</xs:annotation>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="non-redundant"/>
<xs:enumeration value="n+1"/>
<xs:enumeration value="grid"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
Using Python with an API
from ucsmsdk.ucshandle import UcsHandle
from ucsmsdk.mometa.compute.ComputePsuPolicy import ComputePsuPolicy

# Create a connection handle


handle = UcsHandle("172.16.48.135", "cisco", "cisco")

# Login to the server


handle.login()

# Login to the server


powerpol = ComputePsuPolicy(parent_mo_or_dn= ”org-root" redundancy = 'grid' )
Handle.add_mo(powerpol, modify_present = True)

#commit the configuration and logout


handle.commit()
handle.logout()
<xs:attribute name="redundancy">
<xs:annotation>
<xs:appinfo>
<moProperty value="computePsuDef:redundancy"/>
<label value="Redundancy" default="true"/>
<externAccess value="readWrite"/>
<description value="NO COMMENTS"/>
</xs:appinfo>
</xs:annotation>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="non-redundant"/>
<xs:enumeration value="n+1"/>
<xs:enumeration value="grid"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
PYTHON without the native API

import requests

url = http://172.16.48.135/nuova/
headers = {
'content-type': "application/xml",
'cache-control': "no-cache"
}

data = '<configConfMos inHierarchical="no"><inConfigs><pair\


key="org-root/psu-policy"><computePsuPolicy descr=""\
dn="org-root/psu-policy"policyOwner="local” redundancy="grid"></computePsuPolicy>\
</pair></inConfigs></configConfMos>’

response = requests.post(url, headers=headers, data = data)

<xs:attribute name="redundancy">
<xs:annotation>
<xs:appinfo>
<moProperty value="computePsuDef:redundancy"/>
<label value="Redundancy" default="true"/>
<externAccess value="readWrite"/>
<description value="NO COMMENTS"/>
</xs:appinfo>
</xs:annotation>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="non-redundant"/>
<xs:enumeration value="n+1"/>
<xs:enumeration value="grid"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
Application
Programmable Interface
Lesson 5
Data Maniputation and Extraction
Loading JSON

import simplejson as json

file = "/home/student/parse_json.json"
test = open(file, 'r')
readfile = test.read()
data = json.loads(readfile)
test.close()

print data

{'TOP_OBJ': {'attributes': {'ownerKey': u'', 'name': 'TEST1_OBJECT',


'descr': 'This is a main section', 'ownerTag': u''}, 'children': [{'OBJ1': {'attributes':
{'ownerKey': u'', 'name': 'TEST2_OBJECT', 'descr': 'This is a second section', 'ownerTag': u''}}},
{'OBJ2': {'attributes': {'ownerKey': u'', 'name': 'TEST2_OBJECT',
'descr': 'This is a second section', 'ownerTag': u''}, 'children': [{'SUB_OBJ2':
{'attributes': {'prio': '1', 'type': 'String', 'name': 'TEST3_OBJECT', 'descr': 'This is third section'}}}]}}]}}
Parsing JSON (Keys)
{
"TOP_OBJ": {
"attributes": { import simplejson as json
"descr": "This is a main section",
"name": "TEST1_OBJECT",
"ownerKey": "",
"ownerTag": "" file = "/home/student/parse_json.json"
}, test = open(file, 'r')
"children": [{
"OBJ1": {
readfile = test.read()
"attributes": { data = json.loads(readfile)
"descr": "This is a second section", test.close()
"name": "TEST2_OBJECT",
"ownerKey": "",
"ownerTag": "" data1 = data["TOP_OBJ"]["attributes"]
} print data1["name"]
}
}, {
"OBJ2": {
"attributes": {
"descr": "This is a second section",
"name": "TEST2_OBJECT",
"ownerKey": "",
"ownerTag": ""
},
"children": [{
"SUB_OBJ2": {
"attributes": {
"descr": "This is third section",
"type": "String",
"name": "TEST3_OBJECT",
"prio": "1"
}
}
}]
}
}]
}
}
Parsing JSON (Keys)
{
"TOP_OBJ": {
"attributes": { import simplejson as json
"descr": "This is a main section",
"name": "TEST1_OBJECT",
"ownerKey": "",
"ownerTag": "" file = "/home/student/parse_json.json"
}, test = open(file, 'r')
"children": [{
"OBJ1": {
readfile = test.read()
"attributes": { data = json.loads(readfile)
"descr": "This is a second section", test.close()
"name": "TEST2_OBJECT",
"ownerKey": "",
"ownerTag": "" data1 = data["TOP_OBJ"]["attributes"]
} print data1["name"]
}
}, {
"OBJ2": {
"attributes": {
"descr": "This is a second section",
"name": "TEST2_OBJECT",
"ownerKey": "",
"ownerTag": ""
},
"children": [{
"SUB_OBJ2": {
"attributes": {
"descr": "This is third section",
"type": "String",
"name": "TEST3_OBJECT",
"prio": "1"
}
}
}]
}
}]
}
}
Parsing JSON (Keys)
{
"TOP_OBJ": {
"attributes": { import simplejson as json
"descr": "This is a main section",
"name": "TEST1_OBJECT",
"ownerKey": "",
"ownerTag": "" file = "/home/student/parse_json.json"
}, test = open(file, 'r')
"children": [{
"OBJ1": {
readfile = test.read()
"attributes": { data = json.loads(readfile)
"descr": "This is a second section", test.close()
"name": "TEST2_OBJECT",
"ownerKey": "",
"ownerTag": "" data1 = data["TOP_OBJ"]["attributes"]
} print data1["name"]
}
}, {
"OBJ2": {
"attributes": {
"descr": "This is a second section",
"name": "TEST2_OBJECT",
"ownerKey": "",
"ownerTag": ""
},
"children": [{
"SUB_OBJ2": {
"attributes": {
"descr": "This is third section",
"type": "String",
"name": "TEST3_OBJECT",
"prio": "1"
}
}
}]
}
}]
}
}
Parsing JSON (Keys)
{
"TOP_OBJ": {
"attributes": { import simplejson as json
"descr": "This is a main section",
"name": "TEST1_OBJECT",
"ownerKey": "",
"ownerTag": "" file = "/home/student/parse_json.json"
}, test = open(file, 'r')
"children": [{
"OBJ1": {
readfile = test.read()
"attributes": { data = json.loads(readfile)
"descr": "This is a second section", test.close()
"name": "TEST2_OBJECT",
"ownerKey": "",
"ownerTag": "" data1 = data["TOP_OBJ"]["attributes"]
} print data1["name"]
}
}, {
"OBJ2": {
"attributes": {
"descr": "This is a second section",
"name": "TEST2_OBJECT",
"ownerKey": "",
"ownerTag": ""
},
"children": [{
"SUB_OBJ2": {
"attributes": {
"descr": "This is third section",
"type": "String",
"name": "TEST3_OBJECT",
"prio": "1"
}
}
}]
}
}]
}
}
Parsing JSON (Keys)
{
"TOP_OBJ": {
"attributes": { import simplejson as json
"descr": "This is a main section",
"name": "TEST1_OBJECT",
"ownerKey": "",
"ownerTag": "" file = "/home/student/parse_json.json"
}, test = open(file, 'r')
"children": [{
"OBJ1": {
readfile = test.read()
"attributes": { data = json.loads(readfile)
"descr": "This is a second section", test.close()
"name": "TEST2_OBJECT",
"ownerKey": "",
"ownerTag": "" data1 = data["TOP_OBJ"]["attributes"]
} print data1["name"]
}
}, {
"OBJ2": {
"attributes": {
"descr": "This is a second section",
"name": "TEST2_OBJECT",
"ownerKey": "",
"ownerTag": ""
},
"children": [{
"SUB_OBJ2": {
"attributes": {
"descr": "This is third section",
"type": "String",
"name": "TEST3_OBJECT",
"prio": "1"
}
}
}]
}
}]
}
}
Parsing JSON (Keys)
{
"TOP_OBJ": {
"attributes": { import simplejson as json
"descr": "This is a main section",
"name": "TEST1_OBJECT",
"ownerKey": "",
"ownerTag": "" file = "/home/student/parse_json.json"
}, test = open(file, 'r')
"children": [{
"OBJ1": {
readfile = test.read()
"attributes": { data = json.loads(readfile)
"descr": "This is a second section", test.close()
"name": "TEST2_OBJECT",
"ownerKey": "",
"ownerTag": "" data1 = data["TOP_OBJ"]["attributes"]
} print data1["name"]
}
}, {
"OBJ2": {
"attributes": {
"descr": "This is a second section",
"name": "TEST2_OBJECT",
"ownerKey": "",
"ownerTag": ""
},
"children": [{
"SUB_OBJ2": {
"attributes": {
"descr": "This is third section",
"type": "String",
"name": "TEST3_OBJECT",
"prio": "1"
}
}
}]
}
}]
}
}
Parsing JSON (Keys)
{
"TOP_OBJ": {
"attributes": { import simplejson as json
"descr": "This is a main section",
"name": "TEST1_OBJECT",
"ownerKey": "",
"ownerTag": "" file = "/home/student/parse_json.json"
}, test = open(file, 'r')
"children": [{
"OBJ1": {
readfile = test.read()
"attributes": { data = json.loads(readfile)
"descr": "This is a second section", test.close()
"name": "TEST2_OBJECT",
"ownerKey": "",
"ownerTag": "" data1 = data["TOP_OBJ"]["attributes"]
} print data1["name"]
}
}, {
"OBJ2": {
"attributes": {
"descr": "This is a second section",
"name": "TEST2_OBJECT",
"ownerKey": "",
"ownerTag": ""
},
"children": [{
"SUB_OBJ2": {
"attributes": {
"descr": "This is third section",
"type": "String",
"name": "TEST3_OBJECT",
"prio": "1"
}
}
}]
}
}]
}
}
Parsing JSON(Lists)
{
"TOP_OBJ": { import simplejson as json
"attributes": {
"descr": "This is a main section",
"name": "TEST1_OBJECT",
"ownerKey": "", file = "/home/student/parse_json.json"
"ownerTag": ""
},
test = open(file, 'r')
"children": [{ readfile = test.read()
"OBJ1": { data = json.loads(readfile)
"attributes": {
"descr": "This is a second section",
test.close()
"name": "TEST2_OBJECT",
"ownerKey": "", data1 = data["TOP_OBJ"]["children"]
"ownerTag": ""
}
print data1[0]
} print data1[1]
}, {
"OBJ2": {
"attributes": {
"descr": "This is a second section",
"name": "TEST2_OBJECT",
"ownerKey": "",
"ownerTag": ""
},
"children": [{
"SUB_OBJ2": {
"attributes": {
"descr": "This is third section",
"type": "String",
"name": "TEST3_OBJECT",
"prio": "1"
}
}
}]
}
}]
}
}
Parsing JSON (Keys)
{
"TOP_OBJ": { import simplejson as json
"attributes": {
"descr": "This is a main section",
"name": "TEST1_OBJECT",
"ownerKey": "", file = "/home/student/parse_json.json"
"ownerTag": ""
},
test = open(file, 'r')
"children": [{ readfile = test.read()
"OBJ1": { data = json.loads(readfile)
"attributes": {
"descr": "This is a second section",
test.close()
"name": "TEST2_OBJECT",
"ownerKey": "", data1 = data["TOP_OBJ"]["chidren"]
"ownerTag": ""
}
print data1[0]
} print data1[1]
}, {
"OBJ2": {
"attributes": {
"descr": "This is a second section",
"name": "TEST2_OBJECT",
"ownerKey": "",
"ownerTag": ""
},
"children": [{
"SUB_OBJ2": {
"attributes": {
"descr": "This is third section",
"type": "String",
"name": "TEST3_OBJECT",
"prio": "1"
}
}
}]
}
}]
}
}
Parsing JSON (Keys)
{
"TOP_OBJ": { import simplejson as json
"attributes": {
"descr": "This is a main section",
"name": "TEST1_OBJECT",
"ownerKey": "", file = "/home/student/parse_json.json"
"ownerTag": ""
},
test = open(file, 'r')
"children": [{ readfile = test.read()
"OBJ1": { data = json.loads(readfile)
"attributes": {
"descr": "This is a second section",
test.close()
"name": "TEST2_OBJECT",
"ownerKey": "", data1 = data["TOP_OBJ"]["chidren"]
"ownerTag": ""
}
print data1[0]
} print data1[1]
}, {
"OBJ2": {
"attributes": {
"descr": "This is a second section",
"name": "TEST2_OBJECT",
"ownerKey": "",
"ownerTag": ""
},
"children": [{
"SUB_OBJ2": {
"attributes": {
"descr": "This is third section",
"type": "String",
"name": "TEST3_OBJECT",
"prio": "1"
}
}
}]
}
}]
}
}
Parsing JSON (Keys)
{
"TOP_OBJ": { import simplejson as json
"attributes": {
"descr": "This is a main section",
"name": "TEST1_OBJECT",
"ownerKey": "", file = "/home/student/parse_json.json"
"ownerTag": ""
},
test = open(file, 'r')
"children": [{ readfile = test.read()
"OBJ1": { data = json.loads(readfile)
"attributes": {
"descr": "This is a second section",
test.close()
"name": "TEST2_OBJECT",
"ownerKey": "", data1 = data["TOP_OBJ"]["chidren"]
"ownerTag": ""
}
print data1[0]
} print data1[1]
}, {
"OBJ2": {
"attributes": {
"descr": "This is a second section",
"name": "TEST2_OBJECT",
"ownerKey": "",
"ownerTag": ""
},
"children": [{
"SUB_OBJ2": {
"attributes": {
"descr": "This is third section",
"type": "String",
"name": "TEST3_OBJECT",
"prio": "1"
}
}
}]
}
}]
}
}
Parsing JSON (Keys)
{
"TOP_OBJ": { import simplejson as json
"attributes": {
"descr": "This is a main section",
"name": "TEST1_OBJECT",
"ownerKey": "", file = "/home/student/parse_json.json"
"ownerTag": ""
},
test = open(file, 'r')
"children": [{ readfile = test.read()
"OBJ1": { data = json.loads(readfile)
"attributes": {
"descr": "This is a second section",
test.close()

INDEX “0” "name": "TEST2_OBJECT",


"ownerKey": "",
"ownerTag": ""
data1 = data["TOP_OBJ"]["chidren"]
}
print data1[0]
} print data1[1]
}, {
"OBJ2": {
"attributes": {
"descr": "This is a second section",
"name": "TEST2_OBJECT",
"ownerKey": "",
"ownerTag": ""
},
"children": [{
"SUB_OBJ2": {
"attributes": {
"descr": "This is third section",
"type": "String",
"name": "TEST3_OBJECT",
"prio": "1"
}
}
}]
}
}]
}
}
Parsing JSON (Keys)
{
"TOP_OBJ": { import simplejson as json
"attributes": {
"descr": "This is a main section",
"name": "TEST1_OBJECT",
"ownerKey": "", file = "/home/student/parse_json.json"
"ownerTag": ""
},
test = open(file, 'r')
"children": [{ readfile = test.read()
"OBJ1": { data = json.loads(readfile)
"attributes": {
"descr": "This is a second section",
test.close()
"name": "TEST2_OBJECT",
"ownerKey": "", data1 = data["TOP_OBJ"]["chidren"]
"ownerTag": ""
}
print data1[0]
} print data1[1]
}, {
"OBJ2": {
"attributes": {
"descr": "This is a second section",
"name": "TEST2_OBJECT",

INDEX “1” },
"ownerKey": "",
"ownerTag": ""

"children": [{
"SUB_OBJ2": {
"attributes": {
"descr": "This is third section",
"type": "String",
"name": "TEST3_OBJECT",
"prio": "1"
}
}
}]
}
}]
}
}