JW_FLT_KV

Table of Contents

JW_FLT_KV

Description

Write a key and float value to a JSON object.

Parameters

NameDirectionDescription
jin,outThe target string to append to.
kinKey name.
finFloating-point value.

Usage example (from documentation)

  JW_FLT_KV(json, "pi", 3.14159);

Success

Appends a key-value float pair

Failure

Does not return on failure

Usage example (Cross-references)

    JW_OBJ(json, {
    JW_INT_KV(json, "count", count);
    JW_FLT_KV(json, "score", score);
    JW_INT_KV(json, "year", year);
    });
    JW_INT_KV(json, "age", person.age);
    JW_BOOL_KV(json, "is_active", person.is_active);
    JW_FLT_KV(json, "salary", person.salary);
    });
    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_INT_KV(json, "temp", temp);
    JW_FLT_KV(json, "balance", balance);
    JW_FLT_KV(json, "delta", delta);
    });
    JW_INT_KV(json, "temp", temp);
    JW_FLT_KV(json, "balance", balance);
    JW_FLT_KV(json, "delta", delta);
    });
    JW_OBJ(json, {
    JW_INT_KV(json, "big_int", big_int);
    JW_FLT_KV(json, "big_float", big_float);
    JW_FLT_KV(json, "small_float", small_float);
    });
    JW_INT_KV(json, "big_int", big_int);
    JW_FLT_KV(json, "big_float", big_float);
    JW_FLT_KV(json, "small_float", small_float);
    });
    JW_OBJ(json, {
    JW_INT_KV(json, "int_zero", int_zero);
    JW_FLT_KV(json, "float_zero", float_zero);
    JW_BOOL_KV(json, "bool_false", bool_false);
    });
    
    JW_OBJ(json, {
    JW_FLT_KV(json, "tiny", tiny);
    JW_FLT_KV(json, "huge", huge);
    JW_FLT_KV(json, "zero", zero);
    JW_OBJ(json, {
    JW_FLT_KV(json, "tiny", tiny);
    JW_FLT_KV(json, "huge", huge);
    JW_FLT_KV(json, "zero", zero);
    JW_FLT_KV(json, "negative_tiny", negative_tiny);
    JW_FLT_KV(json, "tiny", tiny);
    JW_FLT_KV(json, "huge", huge);
    JW_FLT_KV(json, "zero", zero);
    JW_FLT_KV(json, "negative_tiny", negative_tiny);
    });
    JW_FLT_KV(json, "huge", huge);
    JW_FLT_KV(json, "zero", zero);
    JW_FLT_KV(json, "negative_tiny", negative_tiny);
    });
    // Single float
    f64 single_float = 3.14;
    JW_OBJ(json4, { JW_FLT_KV(json4, "pi", single_float); });
    
    const char* expected1 = "{\"value\":42}";
    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_OBJ_KV(json, target_key.data, {
    JW_FLT_KV(json, "distance", s->distance);
    JW_INT_KV(json, "nearest_neighbor_analysis_id", s->analysis_id);
    JW_INT_KV(json, "nearest_neighbor_binary_id", s->binary_id);
    
    JW_OBJ_KV(json, target_key.data, {
    JW_FLT_KV(json, "distance", symbol.distance);
    JW_STR_KV(json, "name", symbol.function_name);
    });
    JW_OBJ(json, {
    JW_INT_KV(json, "count", original.count);
    JW_FLT_KV(json, "temperature", original.temperature);
    JW_BOOL_KV(json, "enabled", original.enabled);
    JW_STR_KV(json, "message", original.message);
    JW_INT_KV(json, "negative_int", original.negative_int);
    JW_INT_KV(json, "zero_int", original.zero_int);
    JW_FLT_KV(json, "precise_float", original.precise_float);
    JW_FLT_KV(json, "small_float", original.small_float);
    JW_FLT_KV(json, "negative_float", original.negative_float);
    JW_INT_KV(json, "zero_int", original.zero_int);
    JW_FLT_KV(json, "precise_float", original.precise_float);
    JW_FLT_KV(json, "small_float", original.small_float);
    JW_FLT_KV(json, "negative_float", original.negative_float);
    });
    JW_FLT_KV(json, "precise_float", original.precise_float);
    JW_FLT_KV(json, "small_float", original.small_float);
    JW_FLT_KV(json, "negative_float", original.negative_float);
    });
    JW_INT_KV(json, "age", original_person.age);
    JW_BOOL_KV(json, "is_active", original_person.is_active);
    JW_FLT_KV(json, "salary", original_person.salary);
    });
    });
    JW_INT_KV(json, "age", original.user.age);
    JW_BOOL_KV(json, "is_active", original.user.is_active);
    JW_FLT_KV(json, "salary", original.user.salary);
    });
    JW_OBJ_KV(json, "config", {
    JW_INT_KV(json, "min_int", original.min_int);
    JW_INT_KV(json, "zero", original.zero);
    JW_FLT_KV(json, "zero_float", original.zero_float);
    JW_BOOL_KV(json, "true_val", original.true_val);
    JW_BOOL_KV(json, "false_val", original.false_val);

Share :

Related Posts

JW_INT_KV

JW_INT_KV Description Write a key and integer value to a JSON object.

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

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