JSON/GET

Sets JSON value to a key in an object

Input stack: json key value

Output stack: json

PumpkinDB> "{\"a\": 1}" "a" "2" JSON/SET
"{\"a\": 2}"

Allocation

Allocates for parsing and encoding JSON

Errors

EmptyStack error if there are less than three items on the stack

InvalidValue if supplied JSON is not valid.

InvalidValue if supplied key is not a valid UTF-8 string.

InvalidValue if supplied value is not a valid JSON.

Tests

works : "{\"a\": 1}" "a" "2" JSON/SET "a" JSON/GET "2" EQUAL?.
non_json : ["z" "a" "1" JSON/SET] TRY UNWRAP 0x03 EQUAL?.
invalid_key : ["{}" 0xffff "1" JSON/SET] TRY UNWRAP 0x03 EQUAL?.
invalid_val : ["{}" 0xffff "z" JSON/SET] TRY UNWRAP 0x03 EQUAL?.
empty_stack : [JSON/SET] TRY UNWRAP 0x04 EQUAL?.
empty_stack_1 : ["1" JSON/SET] TRY UNWRAP 0x04 EQUAL?.
empty_stack_2 : ["1" "2" JSON/SET] TRY UNWRAP 0x04 EQUAL?.

results matching ""

    No results matching ""