Skip to content

[Refactor] Replace custom JSON parser in cli_support.cpp with nlohmann::json #963

Closed

Description

@kanhaiya-dct

Request type

Improvement to existing behavior

Problem and use case

Description

While exploring the configuration parsing logic in src/runtime/config/cli_support.cpp, I noticed that the file implements its own custom "Tiny JSON parser" (the Parser struct) along with several custom manual JSON string serializers and string scanners (match_object_end, etc.).
Since the project already includes and heavily relies on the robust nlohmann/json library in other core components (such as the tokenizers and plugins), maintaining a custom 300+ line JSON parser specifically for the CLI configuration is unnecessary. It increases technical debt, adds unnecessary binary size, and is prone to edge-case parsing bugs compared to a fully standard-compliant library.

Motivation & Context

Replacing this custom implementation with nlohmann::json will:

  1. Reduce Code Complexity: Eliminate over 300 lines of custom string manipulation and scanning logic.
  2. Increase Robustness: Delegate JSON parsing to a well-tested, standard-compliant library.
  3. Unify Dependencies: Ensure JSON parsing is handled consistently across the entire TensorRT-Model-Connect codebase.

Proposed outcome

Proposed Solution

  • Remove the custom Parser struct from cli_support.cpp.
  • Remove manual JSON serialization functions (e.g., append_json_escaped_string, try_append_numeric).
  • Refactor parse_layered_json and bundle_to_effective_json to utilize nlohmann::json::parse() and .dump().
  • Map the parsed JSON objects back to the internal std::any variants expected by the ConfigBundle schema.

Model and target details

No response

Alternatives considered

No response

Additional context

No response

Submission checks

  • I searched open and closed issues and found no duplicate request.
  • I removed secrets, private/internal evidence, personal paths, and restricted artifacts.

Activity

  1. added
    enhancement
    on Aug 21, 2026
  2. yifeif-nv commented on Aug 21, 2026

    @yifeif-nv
    Collaborator

    Looks good. Thanks for raising the PR and the contribution! I love those kinds of PRs that remove code rather than adding more.

  3. yifeif-nv commented on Aug 21, 2026

    @yifeif-nv
    Collaborator

    I'll leave this issue open until the remaining related issues are addressed

  4. chaofengw-nv commented on Aug 21, 2026

    @chaofengw-nv
    Collaborator

    @kanhaiya-dct Thanks for your contribution. Inspired by this, I have re‑checked some similar cases and filed relevant issues for tracking.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions