Skip to content

Commit 70390d1

Browse files
update README with IO example
1 parent de16550 commit 70390d1

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,29 @@ JSON.json([2,3])
2626
# "[2,3]"
2727
JSON.json(j)
2828
# "{\"an_array\":[\"string\",9],\"a_number\":5.0}"
29+
30+
# import from a file called employees.json,
31+
# the contents of which are below,
32+
# manipulate, and write to another file
33+
# [
34+
# {
35+
# "id" : 1,
36+
# "salary" : 70000
37+
# },
38+
# {
39+
# "id" : 2,
40+
# "salary" : 80000
41+
# }
42+
# ]
43+
employees = JSON.parsefile("employees.json")
44+
45+
for employee in employees
46+
employee["salary"] = employee["salary"] * 2
47+
end
48+
49+
open("employees_doubled.json", "w") do f
50+
JSON.print(f, employees, 4)
51+
end
2952
```
3053

3154
## Documentation

0 commit comments

Comments
 (0)