static int s_aws_hash_table_to_json()

in source/kms.c [402:431]


static int s_aws_hash_table_to_json(struct json_object *obj, const char *const key, const struct aws_hash_table *map) {
    AWS_PRECONDITION(obj);
    AWS_PRECONDITION(aws_c_string_is_valid(key));
    AWS_PRECONDITION(aws_hash_table_is_valid(map));

    struct json_object *json_obj = json_object_new_object();
    if (json_obj == NULL) {
        return AWS_OP_ERR;
    }

    for (struct aws_hash_iter iter = aws_hash_iter_begin(map); !aws_hash_iter_done(&iter); aws_hash_iter_next(&iter)) {
        const struct aws_string *map_key = iter.element.key;
        const struct aws_string *map_value = iter.element.value;

        if (s_string_to_json(json_obj, aws_string_c_str(map_key), aws_string_c_str(map_value)) != AWS_OP_SUCCESS) {
            goto clean_up;
        }
    }

    if (json_object_object_add(obj, key, json_obj) < 0) {
        goto clean_up;
    }

    return AWS_OP_SUCCESS;

clean_up:
    json_object_put(json_obj);

    return AWS_OP_ERR;
}