diff options
Diffstat (limited to 'src/json.c')
-rw-r--r-- | src/json.c | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/src/json.c b/src/json.c index 3a5de7092c..c9a6230d26 100644 --- a/src/json.c +++ b/src/json.c @@ -1127,3 +1127,52 @@ json_find_end(js_read_T *reader, int options) return ret; } #endif + +/* + * "js_decode()" function + */ + void +f_js_decode(typval_T *argvars, typval_T *rettv) +{ + js_read_T reader; + + reader.js_buf = tv_get_string(&argvars[0]); + reader.js_fill = NULL; + reader.js_used = 0; + if (json_decode_all(&reader, rettv, JSON_JS) != OK) + emsg(_(e_invarg)); +} + +/* + * "js_encode()" function + */ + void +f_js_encode(typval_T *argvars, typval_T *rettv) +{ + rettv->v_type = VAR_STRING; + rettv->vval.v_string = json_encode(&argvars[0], JSON_JS); +} + +/* + * "json_decode()" function + */ + void +f_json_decode(typval_T *argvars, typval_T *rettv) +{ + js_read_T reader; + + reader.js_buf = tv_get_string(&argvars[0]); + reader.js_fill = NULL; + reader.js_used = 0; + json_decode_all(&reader, rettv, 0); +} + +/* + * "json_encode()" function + */ + void +f_json_encode(typval_T *argvars, typval_T *rettv) +{ + rettv->v_type = VAR_STRING; + rettv->vval.v_string = json_encode(&argvars[0], 0); +} |