Skip to content

Commit 6c32736

Browse files
committed
use jsonencode(), jsondecode()
1 parent 5726e82 commit 6c32736

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

autoload/webapi/json.vim

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ endfunction
6565

6666
function! webapi#json#decode(json) abort
6767
let json = iconv(a:json, "utf-8", &encoding)
68+
if exists('*jsondecode')
69+
" TODO: handle encoding if vim change the behavior
70+
return jsondecode(json)
71+
endif
6872
if get(g:, 'webapi#json#parse_strict', 1) == 1 && substitute(substitute(substitute(
6973
\ json,
7074
\ '\\\%(["\\/bfnrt]\|u[0-9a-fA-F]\{4}\)', '\@', 'g'),
@@ -102,6 +106,9 @@ function! webapi#json#decode(json) abort
102106
endfunction
103107

104108
function! webapi#json#encode(val) abort
109+
if exists('*jsonencode')
110+
return jsonencode(a:val)
111+
endif
105112
if type(a:val) == 0
106113
return a:val
107114
elseif type(a:val) == 1

0 commit comments

Comments
 (0)