JW_ARR_KV

Table of Contents

JW_ARR_KV

Description

Write a key and an array value into a JSON object. Intended for use within a JW_OBJ. Adds commas automatically.

Parameters

NameDirectionDescription
jin,outThe target string to append to.
kinKey name for the array.
arrinA vector to iterate over.
itemoutIterator variable for the current item.
writerinCode block that appends JSON for each item.

Usage example (from documentation)

  JW_ARR_KV(json, "tags", tag_vec, tag, {
      JW_STR(json, tag);
  });

Success

Appends a key-value array pair to json

Failure

Does not return on failure

Usage example (Cross-references)

    
    JW_OBJ(json, {
    JW_ARR_KV(json, "functions", functions, func, {
    JW_OBJ(json, {
    JW_INT_KV(json, "id", func.id);
    JW_INT_KV(json, "analysis_id", result.analysis_id);
    JW_STR_KV(json, "sha256", result.sha256);
    JW_ARR_KV(json, "tags", result.tags, tag, { JW_STR(json, tag); });
    JW_STR_KV(json, "created_at", result.created_at);
    JW_INT_KV(json, "model_id", result.model_id);
    
    JW_OBJ(json, {
    JW_ARR_KV(json, "numbers", numbers, num, { JW_INT(json, num); });
    JW_ARR_KV(json, "strings", strings, str, { JW_STR(json, str); });
    JW_ARR_KV(json, "booleans", booleans, b, { JW_BOOL(json, b); });
    JW_OBJ(json, {
    JW_ARR_KV(json, "numbers", numbers, num, { JW_INT(json, num); });
    JW_ARR_KV(json, "strings", strings, str, { JW_STR(json, str); });
    JW_ARR_KV(json, "booleans", booleans, b, { JW_BOOL(json, b); });
    });
    JW_ARR_KV(json, "numbers", numbers, num, { JW_INT(json, num); });
    JW_ARR_KV(json, "strings", strings, str, { JW_STR(json, str); });
    JW_ARR_KV(json, "booleans", booleans, b, { JW_BOOL(json, b); });
    });
    
    JW_OBJ(json, {
    JW_ARR_KV(json, "numbers", empty_numbers, num, { JW_INT(json, num); });
    JW_ARR_KV(json, "strings", empty_strings, str, { JW_STR(json, str); });
    });
    JW_OBJ(json, {
    JW_ARR_KV(json, "numbers", empty_numbers, num, { JW_INT(json, num); });
    JW_ARR_KV(json, "strings", empty_strings, str, { JW_STR(json, str); });
    });
    }
    );
    JW_ARR_KV(json, "list", empty_list, item, { JW_INT(json, item); });
    JW_OBJ_KV(json, "deep", {
    JW_OBJ_KV(
    );
    JW_OBJ_KV(json, "filled_obj", { JW_INT_KV(json, "x", x_value); });
    JW_ARR_KV(json, "empty_arr", empty_arr, item, { JW_INT(json, item); });
    JW_ARR_KV(json, "filled_arr", filled_arr, item, { JW_INT(json, item); });
    });
    JW_OBJ_KV(json, "filled_obj", { JW_INT_KV(json, "x", x_value); });
    JW_ARR_KV(json, "empty_arr", empty_arr, item, { JW_INT(json, item); });
    JW_ARR_KV(json, "filled_arr", filled_arr, item, { JW_INT(json, item); });
    });
    VecPushBack(&languages, lang3);
    
    JW_OBJ(json, { JW_ARR_KV(json, "languages", languages, lang, { JW_STR(json, lang); }); });
    
    const char *expected = "{\"languages\":[\"C\",\"Python\",\"Rust\"]}";
    JW_STR_KV(json, "name", product.name);
    JW_FLT_KV(json, "price", product.price);
    JW_ARR_KV(json, "tags", product.tags, tag, { JW_STR(json, tag); });
    });
    Str json = StrInit();
    JW_OBJ(json, {
    JW_ARR_KV(json, "numbers", original_numbers, num, { JW_INT(json, num); });
    JW_ARR_KV(json, "strings", original_strings, str, { JW_STR(json, str); });
    });
    JW_OBJ(json, {
    JW_ARR_KV(json, "numbers", original_numbers, num, { JW_INT(json, num); });
    JW_ARR_KV(json, "strings", original_strings, str, { JW_STR(json, str); });
    });
    JW_INT_KV(json, "timeout", original.config.timeout);
    JW_STR_KV(json, "log_level", original.config.log_level);
    JW_ARR_KV(json, "features", original.config.features, feature, { JW_STR(json, feature); });
    });
    JW_ARR_KV(json, "numbers", original.numbers, num, { JW_INT(json, num); });
    JW_ARR_KV(json, "features", original.config.features, feature, { JW_STR(json, feature); });
    });
    JW_ARR_KV(json, "numbers", original.numbers, num, { JW_INT(json, num); });
    JW_ARR_KV(json, "flags", original.flags, flag, { JW_BOOL(json, flag); });
    });
    });
    JW_ARR_KV(json, "numbers", original.numbers, num, { JW_INT(json, num); });
    JW_ARR_KV(json, "flags", original.flags, flag, { JW_BOOL(json, flag); });
    });
    JW_OBJ(json, {
    JW_STR_KV(json, "empty_string", empty_str);
    JW_ARR_KV(json, "empty_numbers", empty_numbers, num, { JW_INT(json, num); });
    JW_ARR_KV(json, "empty_strings", empty_strings, str, { JW_STR(json, str); });
    JW_OBJ_KV(
    JW_STR_KV(json, "empty_string", empty_str);
    JW_ARR_KV(json, "empty_numbers", empty_numbers, num, { JW_INT(json, num); });
    JW_ARR_KV(json, "empty_strings", empty_strings, str, { JW_STR(json, str); });
    JW_OBJ_KV(
    json,

Share :

Related Posts

JW_ARR

JW_ARR Description Write a JSON array from a vector. Each item is rendered using the provided writer. Handles inserting commas between elements.

Read More

JW_OBJ

JW_OBJ Description Begin a JSON object and write key-value entries using JW_*_KV macros. This macro must be used as a wrapper for other JW_*_KV macros to generate a JSON object. Tracks whether commas are needed between entries using an internal flag.

Read More

JW_OBJ_KV

JW_OBJ_KV Description Write a key and nested object inside an existing JSON object. Should be called inside JW_OBJ. Adds commas appropriately based on insertion order.

Read More