JW_STR_KV

Table of Contents

JW_STR_KV

Description

Write a key and string value into a JSON object.

Parameters

NameDirectionDescription
jin,outThe target string to append to.
kinKey name.
sinA Str object containing the value.

Usage example (from documentation)

  JW_STR_KV(json, "username", user.name);

Success

Appends a key-value string pair

Failure

Does not return on failure

Usage example (Cross-references)

    
    JW_OBJ(json, {
    JW_STR_KV(json, "name", name);
    JW_STR_KV(json, "city", city);
    });
    JW_OBJ(json, {
    JW_STR_KV(json, "name", name);
    JW_STR_KV(json, "city", city);
    });
    JW_OBJ(json, {
    JW_INT_KV(json, "id", person.id);
    JW_STR_KV(json, "name", person.name);
    JW_INT_KV(json, "age", person.age);
    JW_BOOL_KV(json, "is_active", person.is_active);
    JW_BOOL_KV(json, "debug_mode", config.debug_mode);
    JW_INT_KV(json, "timeout", config.timeout);
    JW_STR_KV(json, "log_level", config.log_level);
    });
    JW_OBJ(json, {
    JW_OBJ_KV(json, "user", {
    JW_STR_KV(json, "name", data.user.name);
    JW_STR_KV(json, "email", data.user.email);
    });
    JW_OBJ_KV(json, "user", {
    JW_STR_KV(json, "name", data.user.name);
    JW_STR_KV(json, "email", data.user.email);
    });
    JW_BOOL_KV(json, "active", data.active);
    JW_OBJ(json, {
    JW_INT_KV(json, "id", product.id);
    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); });
    
    JW_OBJ(json, {
    JW_STR_KV(json, "name", empty_name);
    JW_STR_KV(json, "description", empty_desc);
    });
    JW_OBJ(json, {
    JW_STR_KV(json, "name", empty_name);
    JW_STR_KV(json, "description", empty_desc);
    });
    
    JW_OBJ(json, {
    JW_STR_KV(json, "path", path);
    JW_STR_KV(json, "message", message);
    JW_STR_KV(json, "data", data);
    JW_OBJ(json, {
    JW_STR_KV(json, "path", path);
    JW_STR_KV(json, "message", message);
    JW_STR_KV(json, "data", data);
    });
    JW_STR_KV(json, "path", path);
    JW_STR_KV(json, "message", message);
    JW_STR_KV(json, "data", data);
    });
    
    JW_OBJ(json, {
    JW_STR_KV(json, "quotes", quotes);
    JW_STR_KV(json, "backslash", backslash);
    JW_STR_KV(json, "newline", newline);
    JW_OBJ(json, {
    JW_STR_KV(json, "quotes", quotes);
    JW_STR_KV(json, "backslash", backslash);
    JW_STR_KV(json, "newline", newline);
    JW_STR_KV(json, "tab", tab);
    JW_STR_KV(json, "quotes", quotes);
    JW_STR_KV(json, "backslash", backslash);
    JW_STR_KV(json, "newline", newline);
    JW_STR_KV(json, "tab", tab);
    });
    JW_STR_KV(json, "backslash", backslash);
    JW_STR_KV(json, "newline", newline);
    JW_STR_KV(json, "tab", tab);
    });
    // Single string
    Str single_str = StrInitFromZstr("hello");
    JW_OBJ(json2, { JW_STR_KV(json2, "text", single_str); });
    
    // Single boolean
    JW_INT_KV(json, "id", data.user.id);
    JW_OBJ_KV(json, "profile", {
    JW_STR_KV(json, "name", data.user.profile.name);
    JW_INT_KV(json, "age", data.user.profile.age);
    });
    });
    });
    JW_STR_KV(json, "status", data.status);
    });
    JW_OBJ_KV(json, "departments", {
    JW_OBJ_KV(json, "engineering", {
    JW_STR_KV(json, "head", data.company.departments.engineering.head);
    JW_INT_KV(json, "count", data.company.departments.engineering.count);
    JW_FLT_KV(json, "budget", data.company.departments.engineering.budget);
    });
    });
    JW_STR_KV(json, "name", data.company.name);
    });
    });
    JW_OBJ(json, {
    JW_BOOL_KV(json, "status", response.status);
    JW_STR_KV(json, "message", response.message);
    JW_OBJ_KV(json, "data", {
    // Write dynamic key for source function ID
    JW_INT_KV(json, "nearest_neighbor_analysis_id", s->analysis_id);
    JW_INT_KV(json, "nearest_neighbor_binary_id", s->binary_id);
    JW_STR_KV(json, "nearest_neighbor_analysis_name", s->analysis_name);
    JW_STR_KV(json, "nearest_neighbor_function_name", s->function_name);
    JW_STR_KV(json, "nearest_neighbor_sha_256_hash", s->sha256);
    JW_INT_KV(json, "nearest_neighbor_binary_id", s->binary_id);
    JW_STR_KV(json, "nearest_neighbor_analysis_name", s->analysis_name);
    JW_STR_KV(json, "nearest_neighbor_function_name", s->function_name);
    JW_STR_KV(json, "nearest_neighbor_sha_256_hash", s->sha256);
    JW_BOOL_KV(json, "nearest_neighbor_debug", s->debug);
    JW_STR_KV(json, "nearest_neighbor_analysis_name", s->analysis_name);
    JW_STR_KV(json, "nearest_neighbor_function_name", s->function_name);
    JW_STR_KV(json, "nearest_neighbor_sha_256_hash", s->sha256);
    JW_BOOL_KV(json, "nearest_neighbor_debug", s->debug);
    JW_STR_KV(json, "nearest_neighbor_function_name_mangled", s->function_mangled_name);
    JW_STR_KV(json, "nearest_neighbor_sha_256_hash", s->sha256);
    JW_BOOL_KV(json, "nearest_neighbor_debug", s->debug);
    JW_STR_KV(json, "nearest_neighbor_function_name_mangled", s->function_mangled_name);
    });
    JW_OBJ(json, {
    JW_INT_KV(json, "id", func.id);
    JW_STR_KV(json, "name", func.name);
    JW_INT_KV(json, "size", func.size);
    JW_INT_KV(json, "vaddr", func.vaddr);
    JW_OBJ(json, {
    JW_INT_KV(json, "binary_id", result.binary_id);
    JW_STR_KV(json, "binary_name", result.binary_name);
    JW_INT_KV(json, "analysis_id", result.analysis_id);
    JW_STR_KV(json, "sha256", result.sha256);
    JW_STR_KV(json, "binary_name", result.binary_name);
    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_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_STR_KV(json, "model_name", result.model_name);
    JW_STR_KV(json, "created_at", result.created_at);
    JW_INT_KV(json, "model_id", result.model_id);
    JW_STR_KV(json, "model_name", result.model_name);
    JW_STR_KV(json, "owned_by", result.owned_by);
    });
    JW_INT_KV(json, "model_id", result.model_id);
    JW_STR_KV(json, "model_name", result.model_name);
    JW_STR_KV(json, "owned_by", result.owned_by);
    });
    JW_OBJ_KV(json, target_key.data, {
    JW_FLT_KV(json, "distance", symbol.distance);
    JW_STR_KV(json, "name", symbol.function_name);
    });
    JW_OBJ_KV(json, "level2", {
    JW_OBJ_KV(json, "level3", {
    JW_STR_KV(json, "message", deep_message);
    JW_INT_KV(json, "value", 42);
    });
    JW_BOOL_KV(json, "flag", true);
    });
    JW_STR_KV(json, "name", test_name);
    });
    });
    JW_FLT_KV(json, "temperature", original.temperature);
    JW_BOOL_KV(json, "enabled", original.enabled);
    JW_STR_KV(json, "message", original.message);
    });
    Str json = StrInit();
    JW_OBJ(json, {
    JW_STR_KV(json, "empty", original.empty);
    JW_STR_KV(json, "simple", original.simple);
    JW_STR_KV(json, "with_spaces", original.with_spaces);
    JW_OBJ(json, {
    JW_STR_KV(json, "empty", original.empty);
    JW_STR_KV(json, "simple", original.simple);
    JW_STR_KV(json, "with_spaces", original.with_spaces);
    JW_STR_KV(json, "with_special", original.with_special);
    JW_STR_KV(json, "empty", original.empty);
    JW_STR_KV(json, "simple", original.simple);
    JW_STR_KV(json, "with_spaces", original.with_spaces);
    JW_STR_KV(json, "with_special", original.with_special);
    });
    JW_STR_KV(json, "simple", original.simple);
    JW_STR_KV(json, "with_spaces", original.with_spaces);
    JW_STR_KV(json, "with_special", original.with_special);
    });
    JW_OBJ_KV(json, "user", {
    JW_INT_KV(json, "id", original_person.id);
    JW_STR_KV(json, "name", original_person.name);
    JW_INT_KV(json, "age", original_person.age);
    JW_BOOL_KV(json, "is_active", original_person.is_active);
    JW_OBJ_KV(json, "user", {
    JW_INT_KV(json, "id", original.user.id);
    JW_STR_KV(json, "name", original.user.name);
    JW_INT_KV(json, "age", original.user.age);
    JW_BOOL_KV(json, "is_active", original.user.is_active);
    JW_BOOL_KV(json, "debug_mode", original.config.debug_mode);
    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); });
    });
    Str json = StrInit();
    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); });

Share :

Related Posts

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_ARR_KV

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.

Read More

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