Skip to content

Commit 3caaeda

Browse files
committed
Import users from json file
1 parent 7e6ed51 commit 3caaeda

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

main.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
require 'json'
2+
3+
4+
def get_users(file_path)
5+
begin
6+
users_file = File.read(file_path)
7+
users_hash = JSON.parse(users_file)
8+
print "Users imported successfully\n"
9+
return users_hash
10+
rescue JSON::ParserError
11+
print "Error when parsing the users file\n"
12+
rescue Exception
13+
print "Error when reading from the file path given\n"
14+
end
15+
end
16+
17+
18+
19+
users = get_users('./users.json')

0 commit comments

Comments
 (0)