MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / json_append_object

Function json_append_object

deps/lua/src/lua_cjson.c:618–657  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

616}
617
618static void json_append_object(lua_State *l, json_config_t *cfg,
619 int current_depth, strbuf_t *json)
620{
621 int comma, keytype;
622
623 /* Object */
624 strbuf_append_char(json, '{');
625
626 lua_pushnil(l);
627 /* table, startkey */
628 comma = 0;
629 while (lua_next(l, -2) != 0) {
630 if (comma)
631 strbuf_append_char(json, ',');
632 else
633 comma = 1;
634
635 /* table, key, value */
636 keytype = lua_type(l, -2);
637 if (keytype == LUA_TNUMBER) {
638 strbuf_append_char(json, '"');
639 json_append_number(l, cfg, json, -2);
640 strbuf_append_mem(json, "\":", 2);
641 } else if (keytype == LUA_TSTRING) {
642 json_append_string(l, json, -2);
643 strbuf_append_char(json, ':');
644 } else {
645 json_encode_exception(l, cfg, json, -2,
646 "table key must be a number or string");
647 /* never returns */
648 }
649
650 /* table, key, value */
651 json_append_data(l, cfg, current_depth, json);
652 lua_pop(l, 1);
653 /* table, key */
654 }
655
656 strbuf_append_char(json, '}');
657}
658
659/* Serialise Lua data into JSON string. */
660static void json_append_data(lua_State *l, json_config_t *cfg,

Callers 1

json_append_dataFunction · 0.85

Calls 9

strbuf_append_charFunction · 0.85
lua_pushnilFunction · 0.85
lua_nextFunction · 0.85
lua_typeFunction · 0.85
json_append_numberFunction · 0.85
strbuf_append_memFunction · 0.85
json_append_stringFunction · 0.85
json_encode_exceptionFunction · 0.85
json_append_dataFunction · 0.85

Tested by

no test coverage detected