JSON
JavaScript Object Notation
Watch a video?
• Want to watch a video?
• YouTube: https://youtu.be/NvqD0wdQlYA
Human?
• Are you a
human or a
robot?
• Machines
struggle with
unformatted
data
JSON-Udemy.pdf
•Manufacturer: Tesla
•Model: X
•Color: White
•Fuel: Electric
•MPG city: 99
•MPG highway: 93
JSON Data
• JSON data is written as name/value pairs:
• A name / value pair consists of a field
name (in double quotes), followed by a
colon, followed by a value:
• "firstname" : "David"
• Or, "lastname" : "Bombal"
JSON Data types: Object
• Object
• Unordered collection of key:value pairs
• Data surrounded by curly braces { }
• Key and value are separated by a colon
• Each key/value pair is separated by a comma (not the last!). Trailing
commas must not be used.
• Use double quotes, not single quotes.
• Boolean values must be lowercase (different to Python)
• Example:
• {"firstName": "David", "lastName": "Bombal"}
JSON Data types: Object
• Object
• Another example:
{
"firstName" : "David",
"lastName" : "Bombal",
"website" : "davidbombal.com"
}
JSON Data types
• Array
• Ordered list of values
• Uses square brackets [ ]
• Can store multiple types:
• JSON array can store valid JSON data types
such as string, number, Boolean, object, null or
another array
• Values must be separated by comma.
Practical
• Use the DevNet Nexus always on sandbox
• DNS name: sbx-nxos-mgmt.cisco.com
• Protocol: SSH
• Port: 8181
• Username: admin
• Password: Admin_1234!
• Example:
• Mac: ssh -p 8181 admin@sbx-nxos-mgmt.cisco.com
• Windows: Use Putty to connect
JSON Data types
• Object
• Unordered collection of key:value pairs
• Data surrounded by curly braces { }
• show version | json-pretty
{
"chassis_id": "Nexus9000 9000v Chassis",
"cpu_name": "Intel(R) Xeon(R) CPU E5-4669 v4 @ 2.20GHz",
"manufacturer": "Cisco Systems, Inc."
}
JSON Data types
• Object
• Unordered collection
of key:value pairs
• Data surrounded by
curly braces { }
JSON Data types
• Object
• Unordered collection
of key:value pairs
JSON Data types
• Array
• Ordered list of values
• Uses square brackets [ ]
Python Script 1
• Run Python On-Box :
from cli import *
cmd1 = 'show ip int brief | json-pretty'
output1 = cli(cmd1)
print(output1)
Python Script 2
• Run Python On-Box :
• Extract
•TABLE_intf dictionary
•ROW_intf dictionary
• Select element in the index
• Select the key
Python Script 2
• Run Python On-Box :
from cli import *
import json
cmd1 = 'show ip int brief | json-pretty'
json_data = cli(cmd1)
json_final = json.loads(json_data)
print(json_final['TABLE_intf']['ROW_intf'][0]['prefix'])
Python Script 3 Step 1
• Run Python remotely using Ubuntu:
• Step 1: Install Python and Netmiko
sudo apt install python3-pip
sudo pip3 install -U netmiko
Python Script 3 Step 2
• Run Python remotely using Ubuntu VM: Print out interfaces to test our script:
#!/usr/bin/env python
from netmiko import ConnectHandler
nx_os = {
'device_type': 'cisco_ios',
'ip': 'sbx-nxos-mgmt.cisco.com',
'username': 'admin',
'password': 'Admin_1234!',
'port': 8181
}
net_connect = ConnectHandler(**nx_os)
output = net_connect.send_command('show ip int brief')
print(output)
Python Script 4
• Print JSON output:
#!/usr/bin/env python
from netmiko import ConnectHandler
nx_os = {
'device_type': 'cisco_ios',
'ip': 'sbx-nxos-mgmt.cisco.com',
'username': 'admin',
'password': 'Admin_1234!',
'port': 8181
}
net_connect = ConnectHandler(**nx_os)
output = net_connect.send_command('show ip int brief | json-pretty')
print(output)
Python Script 5
• Find some data:
#!/usr/bin/env python
from netmiko import ConnectHandler
import json
nx_os = {
'device_type': 'cisco_ios',
'ip': 'sbx-nxos-mgmt.cisco.com',
'username': 'admin',
'password': 'Admin_1234!',
'port': 8181
}
net_connect = ConnectHandler(**nx_os)
output = net_connect.send_command('show ip int brief | json-pretty')
json_data = json.loads(output)
print(json_data['TABLE_intf']['ROW_intf'][0]['intf-name'])
print(json_data['TABLE_intf']['ROW_intf'][0]['prefix'])
Python Script 6 Part 1
• Use a loop to find IP addresses :
#!/usr/bin/env python
from netmiko import ConnectHandler
import json
nx_os = {
'device_type': 'cisco_ios',
'ip': 'sbx-nxos-mgmt.cisco.com',
'username': 'admin',
'password': 'Admin_1234!',
'port': 8181
}
Python Script 6 Part 2
• Use a loop to find IP addresses :
net_connect = ConnectHandler(**nx_os)
output = net_connect.send_command('show ip int brief | json-
pretty')
json_data = json.loads(output)
int_number = len(json_data['TABLE_intf']['ROW_intf'])
for x in range(int_number):
print(json_data['TABLE_intf']['ROW_intf'][x]['intf-name'])
print(json_data['TABLE_intf']['ROW_intf'][x]['prefix'])
JSON
JavaScript Object Notation

More Related Content

PPTX
TypeScript
PPTX
NAVTechDays 2017 Json Meets NAV
PPTX
Angular2 for Beginners
PDF
C# Language Overview Part I
PPT
json.ppt download for free for college project
PDF
Kotlin Starter Pack
PPTX
c#(loops,arrays)
PDF
Json the-x-in-ajax1588
TypeScript
NAVTechDays 2017 Json Meets NAV
Angular2 for Beginners
C# Language Overview Part I
json.ppt download for free for college project
Kotlin Starter Pack
c#(loops,arrays)
Json the-x-in-ajax1588

Similar to JSON-Udemy.pdf (20)

PDF
Testing swagger contracts without contract based testing
PDF
Use JSON to Slash Your Database Performance.pdf
PDF
FIFA fails, Guy Kawasaki and real estate in SF - find out about all three by ...
PPTX
CSV JSON and XML files in Python.pptx
PPTX
Functional verification using System verilog introduction
PDF
Rapid Data Modeling and Testing with FakeIt
PDF
A simple and powerful property system for C++ (talk at GCDC 2008, Leipzig)
PPT
Data types and Operators
PDF
C++ Chapter I
ODP
GDC 2010 - A Dynamic Component Architecture for High Performance Gameplay - M...
PPTX
19csharp
PPTX
PDF
GraphQL – the future of APIs?
PPTX
Reviewing a Complex DataWeave Transformation Use-case v2
PDF
React Native One Day
PDF
Володимир Гоцик. Getting maximum of python, django with postgres 9.4. PyCon B...
PPTX
JSON
PDF
How to become a Kotlin developer in 10 mins
PPT
GDC 2010 - A Dynamic Component Architecture for High Performance Gameplay
PDF
IntroToEngineDevelopment.pdf
Testing swagger contracts without contract based testing
Use JSON to Slash Your Database Performance.pdf
FIFA fails, Guy Kawasaki and real estate in SF - find out about all three by ...
CSV JSON and XML files in Python.pptx
Functional verification using System verilog introduction
Rapid Data Modeling and Testing with FakeIt
A simple and powerful property system for C++ (talk at GCDC 2008, Leipzig)
Data types and Operators
C++ Chapter I
GDC 2010 - A Dynamic Component Architecture for High Performance Gameplay - M...
19csharp
GraphQL – the future of APIs?
Reviewing a Complex DataWeave Transformation Use-case v2
React Native One Day
Володимир Гоцик. Getting maximum of python, django with postgres 9.4. PyCon B...
JSON
How to become a Kotlin developer in 10 mins
GDC 2010 - A Dynamic Component Architecture for High Performance Gameplay
IntroToEngineDevelopment.pdf
Ad

Recently uploaded (20)

PPTX
Reproductive system-Human anatomy and physiology
PDF
African Communication Research: A review
PPTX
Integrated Management of Neonatal and Childhood Illnesses (IMNCI) – Unit IV |...
PPTX
UNIT_2-__LIPIDS[1].pptx.................
PDF
The TKT Course. Modules 1, 2, 3.for self study
DOCX
Ibrahim Suliman Mukhtar CV5AUG2025.docx
PDF
Fun with Grammar (Communicative Activities for the Azar Grammar Series)
PDF
LIFE & LIVING TRILOGY - PART - (2) THE PURPOSE OF LIFE.pdf
PDF
Journal of Dental Science - UDMY (2020).pdf
PDF
1.Salivary gland disease.pdf 3.Bleeding and Clotting Disorders.pdf important
PDF
Controlled Drug Delivery System-NDDS UNIT-1 B.Pharm 7th sem
PDF
MICROENCAPSULATION_NDDS_BPHARMACY__SEM VII_PCI Syllabus.pdf
PDF
semiconductor packaging in vlsi design fab
PPTX
What’s under the hood: Parsing standardized learning content for AI
PDF
THE CHILD AND ADOLESCENT LEARNERS & LEARNING PRINCIPLES
DOCX
Cambridge-Practice-Tests-for-IELTS-12.docx
PPTX
PLASMA AND ITS CONSTITUENTS 123.pptx
PDF
Skin Care and Cosmetic Ingredients Dictionary ( PDFDrive ).pdf
PDF
Disorder of Endocrine system (1).pdfyyhyyyy
PPTX
Macbeth play - analysis .pptx english lit
Reproductive system-Human anatomy and physiology
African Communication Research: A review
Integrated Management of Neonatal and Childhood Illnesses (IMNCI) – Unit IV |...
UNIT_2-__LIPIDS[1].pptx.................
The TKT Course. Modules 1, 2, 3.for self study
Ibrahim Suliman Mukhtar CV5AUG2025.docx
Fun with Grammar (Communicative Activities for the Azar Grammar Series)
LIFE & LIVING TRILOGY - PART - (2) THE PURPOSE OF LIFE.pdf
Journal of Dental Science - UDMY (2020).pdf
1.Salivary gland disease.pdf 3.Bleeding and Clotting Disorders.pdf important
Controlled Drug Delivery System-NDDS UNIT-1 B.Pharm 7th sem
MICROENCAPSULATION_NDDS_BPHARMACY__SEM VII_PCI Syllabus.pdf
semiconductor packaging in vlsi design fab
What’s under the hood: Parsing standardized learning content for AI
THE CHILD AND ADOLESCENT LEARNERS & LEARNING PRINCIPLES
Cambridge-Practice-Tests-for-IELTS-12.docx
PLASMA AND ITS CONSTITUENTS 123.pptx
Skin Care and Cosmetic Ingredients Dictionary ( PDFDrive ).pdf
Disorder of Endocrine system (1).pdfyyhyyyy
Macbeth play - analysis .pptx english lit
Ad

JSON-Udemy.pdf

  • 2. Watch a video? • Want to watch a video? • YouTube: https://youtu.be/NvqD0wdQlYA
  • 3. Human? • Are you a human or a robot? • Machines struggle with unformatted data
  • 5. •Manufacturer: Tesla •Model: X •Color: White •Fuel: Electric •MPG city: 99 •MPG highway: 93
  • 6. JSON Data • JSON data is written as name/value pairs: • A name / value pair consists of a field name (in double quotes), followed by a colon, followed by a value: • "firstname" : "David" • Or, "lastname" : "Bombal"
  • 7. JSON Data types: Object • Object • Unordered collection of key:value pairs • Data surrounded by curly braces { } • Key and value are separated by a colon • Each key/value pair is separated by a comma (not the last!). Trailing commas must not be used. • Use double quotes, not single quotes. • Boolean values must be lowercase (different to Python) • Example: • {"firstName": "David", "lastName": "Bombal"}
  • 8. JSON Data types: Object • Object • Another example: { "firstName" : "David", "lastName" : "Bombal", "website" : "davidbombal.com" }
  • 9. JSON Data types • Array • Ordered list of values • Uses square brackets [ ] • Can store multiple types: • JSON array can store valid JSON data types such as string, number, Boolean, object, null or another array • Values must be separated by comma.
  • 10. Practical • Use the DevNet Nexus always on sandbox • DNS name: sbx-nxos-mgmt.cisco.com • Protocol: SSH • Port: 8181 • Username: admin • Password: Admin_1234! • Example: • Mac: ssh -p 8181 [email protected] • Windows: Use Putty to connect
  • 11. JSON Data types • Object • Unordered collection of key:value pairs • Data surrounded by curly braces { } • show version | json-pretty { "chassis_id": "Nexus9000 9000v Chassis", "cpu_name": "Intel(R) Xeon(R) CPU E5-4669 v4 @ 2.20GHz", "manufacturer": "Cisco Systems, Inc." }
  • 12. JSON Data types • Object • Unordered collection of key:value pairs • Data surrounded by curly braces { }
  • 13. JSON Data types • Object • Unordered collection of key:value pairs
  • 14. JSON Data types • Array • Ordered list of values • Uses square brackets [ ]
  • 15. Python Script 1 • Run Python On-Box : from cli import * cmd1 = 'show ip int brief | json-pretty' output1 = cli(cmd1) print(output1)
  • 16. Python Script 2 • Run Python On-Box : • Extract •TABLE_intf dictionary •ROW_intf dictionary • Select element in the index • Select the key
  • 17. Python Script 2 • Run Python On-Box : from cli import * import json cmd1 = 'show ip int brief | json-pretty' json_data = cli(cmd1) json_final = json.loads(json_data) print(json_final['TABLE_intf']['ROW_intf'][0]['prefix'])
  • 18. Python Script 3 Step 1 • Run Python remotely using Ubuntu: • Step 1: Install Python and Netmiko sudo apt install python3-pip sudo pip3 install -U netmiko
  • 19. Python Script 3 Step 2 • Run Python remotely using Ubuntu VM: Print out interfaces to test our script: #!/usr/bin/env python from netmiko import ConnectHandler nx_os = { 'device_type': 'cisco_ios', 'ip': 'sbx-nxos-mgmt.cisco.com', 'username': 'admin', 'password': 'Admin_1234!', 'port': 8181 } net_connect = ConnectHandler(**nx_os) output = net_connect.send_command('show ip int brief') print(output)
  • 20. Python Script 4 • Print JSON output: #!/usr/bin/env python from netmiko import ConnectHandler nx_os = { 'device_type': 'cisco_ios', 'ip': 'sbx-nxos-mgmt.cisco.com', 'username': 'admin', 'password': 'Admin_1234!', 'port': 8181 } net_connect = ConnectHandler(**nx_os) output = net_connect.send_command('show ip int brief | json-pretty') print(output)
  • 21. Python Script 5 • Find some data: #!/usr/bin/env python from netmiko import ConnectHandler import json nx_os = { 'device_type': 'cisco_ios', 'ip': 'sbx-nxos-mgmt.cisco.com', 'username': 'admin', 'password': 'Admin_1234!', 'port': 8181 } net_connect = ConnectHandler(**nx_os) output = net_connect.send_command('show ip int brief | json-pretty') json_data = json.loads(output) print(json_data['TABLE_intf']['ROW_intf'][0]['intf-name']) print(json_data['TABLE_intf']['ROW_intf'][0]['prefix'])
  • 22. Python Script 6 Part 1 • Use a loop to find IP addresses : #!/usr/bin/env python from netmiko import ConnectHandler import json nx_os = { 'device_type': 'cisco_ios', 'ip': 'sbx-nxos-mgmt.cisco.com', 'username': 'admin', 'password': 'Admin_1234!', 'port': 8181 }
  • 23. Python Script 6 Part 2 • Use a loop to find IP addresses : net_connect = ConnectHandler(**nx_os) output = net_connect.send_command('show ip int brief | json- pretty') json_data = json.loads(output) int_number = len(json_data['TABLE_intf']['ROW_intf']) for x in range(int_number): print(json_data['TABLE_intf']['ROW_intf'][x]['intf-name']) print(json_data['TABLE_intf']['ROW_intf'][x]['prefix'])