Skip to content

Commit 73549a5

Browse files
committed
Add json_load
1 parent 5285c8e commit 73549a5

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

vm/src/stdlib/json.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ pub fn json_loads(string: PyStringRef, vm: &VirtualMachine) -> PyResult {
3939
})
4040
}
4141

42+
pub fn json_load(fp: PyObjectRef, vm: &VirtualMachine) -> PyResult {
43+
let result = vm.call_method(&fp, "read", vec![])?;
44+
json_loads(result.downcast()?, vm)
45+
}
46+
4247
pub fn make_module(vm: &VirtualMachine) -> PyObjectRef {
4348
let ctx = &vm.ctx;
4449

@@ -53,6 +58,7 @@ pub fn make_module(vm: &VirtualMachine) -> PyObjectRef {
5358
"dumps" => ctx.new_rustfunc(json_dumps),
5459
"dump" => ctx.new_rustfunc(json_dump),
5560
"loads" => ctx.new_rustfunc(json_loads),
61+
"load" => ctx.new_rustfunc(json_load),
5662
"JSONDecodeError" => json_decode_error
5763
})
5864
}

0 commit comments

Comments
 (0)