Skip to content
This repository has been archived by the owner on Oct 25, 2024. It is now read-only.

Read & Write to json file #71

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 42 additions & 3 deletions group.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,44 @@
"""An example of how to represent a group of acquaintances in Python."""
import json

# Your code to go here...
group = {
"Jill": {
"age": 26,
"job": "biologist",
"relations": {
"Zalika": "friend",
"John": "partner"
}
},
"Zalika": {
"age": 28,
"job": "artist",
"relations": {
"Jill": "friend"
}
},
"John": {
"age": 27,
"job": "writer",
"relations": {
"Jill": "partner"
}
},
"Nash": {
"age": 34,
"job": "chef",
"relations": {
"John": "cousin",
"Zalika": "landlord"
}
}
}

my_group =
# write file
with open('group_friends.json', 'w') as json_file:
json.dump(group, json_file, indent=4)


with open('group_friends.json', 'r') as json_file:
group_friends = json_file.read()

print(group_friends)
32 changes: 32 additions & 0 deletions group_friends.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"Jill": {
"age": 26,
"job": "biologist",
"relations": {
"Zalika": "friend",
"John": "partner"
}
},
"Zalika": {
"age": 28,
"job": "artist",
"relations": {
"Jill": "friend"
}
},
"John": {
"age": 27,
"job": "writer",
"relations": {
"Jill": "partner"
}
},
"Nash": {
"age": 34,
"job": "chef",
"relations": {
"John": "cousin",
"Zalika": "landlord"
}
}
}