@@ -143,6 +143,16 @@ static const struct json_obj_descr array_2dim_extra_named_descr[] = {
143143 ARRAY_SIZE (obj_array_descr )),
144144};
145145
146+ struct test_json_tok_encoded_obj {
147+ const char * encoded_obj ;
148+ int ok ;
149+ };
150+
151+ static const struct json_obj_descr test_json_tok_encoded_obj_descr [] = {
152+ JSON_OBJ_DESCR_PRIM (struct test_json_tok_encoded_obj , encoded_obj , JSON_TOK_ENCODED_OBJ ),
153+ JSON_OBJ_DESCR_PRIM (struct test_json_tok_encoded_obj , ok , JSON_TOK_NUMBER ),
154+ };
155+
146156ZTEST (lib_json_test , test_json_encoding )
147157{
148158 struct test_struct ts = {
@@ -1209,4 +1219,23 @@ ZTEST(lib_json_test, test_large_descriptor)
12091219 zassert_true (ret & ((int64_t )1 << 39 ), "Field int39 not decoded" );
12101220}
12111221
1222+ ZTEST (lib_json_test , test_json_encoded_object_tok_encoding )
1223+ {
1224+ static const char encoded [] =
1225+ "{\"encoded_obj\":{\"test\":{\"nested\":\"yes\"}},\"ok\":1234}" ;
1226+ const struct test_json_tok_encoded_obj obj = {
1227+ .encoded_obj = "{\"test\":{\"nested\":\"yes\"}}" ,
1228+ .ok = 1234 ,
1229+ };
1230+ char buffer [sizeof (encoded )];
1231+ int ret ;
1232+
1233+ ret = json_obj_encode_buf (test_json_tok_encoded_obj_descr ,
1234+ ARRAY_SIZE (test_json_tok_encoded_obj_descr ), & obj , buffer ,
1235+ sizeof (buffer ));
1236+
1237+ zassert_equal (ret , 0 , "Encoding function failed" );
1238+ zassert_mem_equal (buffer , encoded , sizeof (encoded ), "Encoded contents not consistent" );
1239+ }
1240+
12121241ZTEST_SUITE (lib_json_test , NULL , NULL , NULL , NULL , NULL );
0 commit comments