Skip to content

Add internal JSON backend layer, autotools integration and backend placeholders#53

Merged
Easton97-Jens merged 5 commits into
v3/master-jsonfrom
codex/implement-json-backend-architecture
Apr 8, 2026
Merged

Add internal JSON backend layer, autotools integration and backend placeholders#53
Easton97-Jens merged 5 commits into
v3/master-jsonfrom
codex/implement-json-backend-architecture

Conversation

@Easton97-Jens

Copy link
Copy Markdown
Owner

Motivation

  • Introduce a pluggable internal JSON layer so YAJL can be gradually removed and multiple C / C++ JSON backends can be selected at build time.
  • Provide build-time control to prefer system vs bundled backends, pick internal JSON operating mode, and enable backend debug traces.

Description

  • Add autotools options and resolution logic (--with-json-c, --with-json-cxx, --with-json-prefer, --with-json-mode, --enable-json-backend-debug) and export build variables JSON_BACKEND_CFLAGS, JSON_BACKEND_LDADD, JSON_BACKEND_LDFLAGS, JSON_C_BACKEND, JSON_CXX_BACKEND, etc., with configure summary output.
  • Implement an internal JSON abstraction under src/json/: json_backend.h/.cc (yajl-compatible writer shim), event-walker json_walk.h/.cc, error/value helpers and many backend registration placeholders under src/json/backends/ (yyjson, json-c, jansson, cjson, nlohmann, jsoncpp, jsoncons, simdjson, glaze, yajl, etc.).
  • Wire JSON sources into the build: add JSON_BACKENDS to src/Makefile.am and inject $(JSON_BACKEND_CFLAGS|LDFLAGS|LDADD) into build flags and libadd; update source callsites to use WITH_JSON_SUPPORT and the new internal API (replace direct YAJL includes/usages in modsecurity.cc and transaction.cc).
  • Add documentation and maintenance helpers: docs/json-backends/* explaining autotools integration and per-backend notes, scripts/import-nlohmannjson.sh (and import-json-c.sh stub), vendored third_party/nlohmann_json single-header (recommended tag), and placeholder third_party/*/README.md files.

Testing

  • Performed configure-time validation by running ./configure with the new JSON options and inspected the configuration summary to confirm backends and preferences are reported; option parsing and validation messages are present.
  • Performed a local build of the project (autotools + make) with the default configure selection to ensure the new sources integrate into the build system and compile; the build completed successfully.

Codex Task

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 121ccb9147

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/json/json_backend.cc
Comment on lines +167 to +169
g->out.push_back('{');
endToken(g);
g->stack.push_back({Frame::Map, true, true});

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Stop toggling parent map state on container open

Calling endToken() in yajl_gen_map_open (and similarly in array open) flips the parent map to expectingKey=true before the nested value is finished, then close flips it again; this leaves the parent in the wrong state after nested objects/arrays. In practice, serializing { "k": { ... }, "next": ... } emits wrong separators and the final yajl_gen_map_close/yajl_gen_get_buf path fails, which breaks JSON generation paths like Transaction::toJSON that rely on nested maps.

Useful? React with 👍 / 👎.

Comment thread configure.ac Outdated
Comment thread src/json/json_backend.cc Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: aff84034d1

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread configure.ac
if test "x$JSON_CXX_BACKEND" = "xnone" && (test "x$with_json_cxx" = "xauto" || test "x$with_json_cxx" = "xglaze"); then
AC_CHECK_HEADER([glaze/glaze.hpp], [JSON_CXX_BACKEND="glaze"; JSON_CXX_BACKEND_SOURCE="system"])
fi
if test "x$JSON_CXX_BACKEND" = "xnone" && test "x$with_json_prefer" != "xsystem" && test -f "${srcdir}/third_party/nlohmann_json/include/nlohmann/json.hpp"; then

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Honor explicit --with-json-cxx backend requests

When an explicit C++ backend is requested (for example --with-json-cxx=jsoncpp) and that backend is not found, this fallback still picks vendored nlohmann if --with-json-prefer is not system. Because third_party/nlohmann_json/include/nlohmann/json.hpp is shipped in-tree, configure succeeds instead of reaching the explicit-request failure path, so builds can silently use a different backend than the one the user asked for.

Useful? React with 👍 / 👎.

Comment thread configure.ac Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f4380f2fdf

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread configure.ac Outdated
Comment thread src/json/json_backend.cc Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: cbb0756333

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread configure.ac
Comment on lines +395 to +397
if test "x$JSON_C_BACKEND" != "xnone"; then
AC_DEFINE([WITH_JSON_SUPPORT], [1], [Define if a JSON backend is enabled for JSON generation])
JSON_BACKEND_CFLAGS="$JSON_BACKEND_CFLAGS $JSON_C_BACKEND_DEFINE $JSON_CXX_BACKEND_DEFINE -DWITH_JSON_SUPPORT"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Keep JSON support enabled when YAJL is the only backend

This gate disables WITH_JSON_SUPPORT whenever JSON_C_BACKEND resolves to none, but the new resolver never includes YAJL in its C-backend candidates. In environments that only have YAJL (a common existing setup), --with-json-c=auto now resolves to none, so Transaction::toJSON and ModSecurity::processContentOffset are compiled out and return the "not compiled with JSON support" path despite YAJL being present. That is a functional regression from the previous YAJL-based JSON generation behavior.

Useful? React with 👍 / 👎.

@Easton97-Jens
Easton97-Jens merged commit 8d6187c into v3/master-json Apr 8, 2026
@Easton97-Jens
Easton97-Jens deleted the codex/implement-json-backend-architecture branch April 8, 2026 12:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant