Skip to content

[json] Parse boolean values as integers - #4275

Merged
liviuchircu merged 3 commits into
OpenSIPS:masterfrom
darwvin-dev:fix/json-boolean-int
Oct 5, 2026
Merged

liviuchircu merged 3 commits into
OpenSIPS:masterfrom
darwvin-dev:fix/json-boolean-int

Conversation

@darwvin-dev

@darwvin-dev darwvin-dev commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Summary
Parse JSON boolean values as OpenSIPS integer pseudo-values (true -> 1, false -> 0) instead of exposing them as strings.

Details
The JSON module currently falls through to JSON serialization for json_type_boolean, so $json(...) returns the strings true / false. This is surprising in script conditionals because both non-empty strings are truthy, and it is inconsistent with the OpenSIPS script true / false placeholders.

Solution
Handle json_type_boolean explicitly in pv_get_json_ext(), using json_object_get_boolean() and exporting the value as both integer and string, matching the existing integer handling semantics.

The module documentation now describes boolean return values and the module test configuration includes regression assertions for both equality and truthiness.

Compatibility
This intentionally changes the pseudo-variable type/value exposed for JSON booleans. Scripts which explicitly compare JSON booleans to the strings "true" or "false" will need to compare against 1/0 or true/false instead.

Validation

  • make include_modules=json modules -j8 builds successfully
  • make app -j8 builds successfully
  • minimal runtime verification returns 1 for JSON true and 0 for JSON false
  • regression assertions were added for true == true, true == 1, truthiness, false == false, false == 0, and falsey evaluation

The local test runner additionally needs the TAP development headers; the regression test is committed for the upstream test environment.

Closing issues
Closes #2744

Migration / validation update

This is intentionally backwards-incompatible. Migration note for the external 4.0 -> 4.1 guide: $json() booleans are now exposed as integer pseudo-values (true as 1, false as 0); configurations comparing them with the literal strings "true" / "false" must be updated. The migration guide is maintained outside this source repository, so this note cannot be included as a source-tree change in this PR.

Revalidated after rebasing onto current master:

  • make include_modules=json modules -j$(nproc) — passed
  • make app -j$(nproc) — passed
  • live OpenSIPS runtime verification — all six boolean equality/truthiness assertions passed
  • git diff --check — passed

Sync with OpenSIPS master before upstream review.
@liviuchircu
liviuchircu merged commit ab46251 into OpenSIPS:master Oct 5, 2026
107 checks passed
@liviuchircu liviuchircu added this to the 4.1.0-beta milestone Oct 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE] json: Boolean values should be parsed as ints, not strings

2 participants