Skip to content

Instantly share code, notes, and snippets.

[
{
"postId": 1,
"id": 1,
"name": "id labore ex et quam laborum",
"email": "Eliseo@gardner.biz",
"body": "laudantium enim quasi est quidem magnam voluptate ipsam eos\ntempora quo necessitatibus\ndolor quam autem quasi\nreiciendis et nam sapiente accusantium"
},
{
"postId": 1,
<?xml version="1.0" encoding="UTF-8"?>
<root>
<element>
<body>laudantium enim quasi est quidem magnam voluptate ipsam eos
tempora quo necessitatibus
dolor quam autem quasi
reiciendis et nam sapiente accusantium</body>
<email>Eliseo@gardner.biz</email>
<id>1</id>
<name>id labore ex et quam laborum</name>
interface Vlan100
description Data VLAN for Access-Switch
ip address 10.1.1.1 255.255.255.0
ip helper-address 10.1.2.1
standby 1 ip 10.1.1.2
interface Vlan100
description Data VLAN for Access-Switch
ip address 10.1.1.1 255.255.255.0
ip helper-address 10.1.2.1
glbp 1 ip 10.1.1.2
<persons>
<element>
<gender>male</gender>
<name>Jeff Bezos</name>
</element>
import xml.etree.ElementTree as ET
tree = ET.parse('persons.xml')
root = tree.getroot()
# total number of nodes from root
print('\nNumber of Nodes:')
print(len(root[0]))
# all nodes data
print('\nNode Data:')
for elem in root:
for subelem in elem:
from xml.dom import minidom
doc = minidom.parse("persons.xml")
elements = doc.getElementsByTagName("element")
for element in elements:
name = element.getElementsByTagName("name")[0]
[
{
"gender": "male",
"name": "Jeff Bezos"
},
import json
with open('persons.json', 'r') as f:
my_dict = json.load(f)
for distro in my_dict:
print(distro['gender'])
---
- gender: male
name: Jeff Bezos
- gender: male
name: Elon Musk