]> git.corax.cc Git - toolbox/commit
include/json: Introduce type specifiers
authorMatthias Kruk <m@m10k.eu>
Wed, 7 Jul 2021 00:18:03 +0000 (09:18 +0900)
committerMatthias Kruk <m@m10k.eu>
Wed, 7 Jul 2021 00:18:03 +0000 (09:18 +0900)
commit318ba9094e4e49c87245d2c770010bf6048bf736
treea910cc9fc569578367b171ab50432f3c017810ed
parent097109bfb7f0797c33beeadd6bf988b608a95e24
include/json: Introduce type specifiers

When constructing JSON objects and arrays, there are cases where the
json_object() and json_array() functions cannot correctly determine
the type of a variable (for example, "true" could be string or bool).
This commit introduces type specifiers that allow the user to declare
the type of a value that is passed to the json functions.
Specifiers are prepended to the value when passing it to the
json_object() json_array() functions. The following specifiers are
understood:

 - "s:" string
 - "i:" integer
 - "b:" boolean
 - "f:" float
 - "o:" object
 - "a:" array

The following is how the specifiers are passed.

 json_object "some_string"  "s:$some_string" \
             "some_integer" "i:$some_integer"

For backwards compatibility, the specifiers may be omitted. In that
case, a best-effort guess will be made. Omitting type specifiers will
make it impossible to pass certain values in strings.
include/json.sh