Skip to content

[Bug]: Trailing raw text corrupts valid JSON #213

Closed

Description

@linkliti

Version of the library

https://mangiucugna.github.io/json_repair/#jr=v1.d.eJyVUkFuwyAQ_Mpqe-DiF1jKH3rorRtF1N7aRAZcWEe1LP5e2ZAmlhJVPYFmZmeXWRY8Y40LofR-6nqJhDW8EwrhsQJC8X44OW15xQm_CX9RHbpNvRCGyYm5aoSDNU4PWdr4tuAv0Hhr2QkMxjGR-xsw8TSubjGaC8MBYtOz1XA4wKJkHlnVoPzHmRtRFagx-JGDGI6qhiVVoHTbGjHe6eH1nnsLEyfClBJWGLf3O1gnn8cyazYlrDIR-GsygdstnGMBb-1yCg5gM7kLsoB7bx2Cnot15oyw3ev3FVGCcR3hlU35kqprz551u0X2rOfe4Va4W-__K29f4EHlLsNMPtrHKpYwcWmwHqkk_Ez-qYfI5NbtWawx6uGiO8b0A6Ad4os

Describe the bug

Extra } or any other text/symbols at the end corrupts valid json, causing tool_args to have extra keys

How to reproduce

input (has extra } at the end, it can be replaced with any raw text)

{"thoughts": ["t"], "tool_name": "x", "tool_args": {"runtime": "terminal", "code": "# comment line\n# comment line\n# comment line\nis_permissive = schema == {'type': 'object', 'properties': {}, 'additionalProperties': True}"}}}

schema

{
  "type": "object",
  "required": [],
  "properties": {
    "thoughts": {
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "headline": {
      "type": "string"
    },
    "tool_name": {
      "type": "string"
    },
    "tool_args": {
      "type": "object",
      "additionalProperties": true
    }
  },
  "additionalProperties": false
}

result (both modes) - extra keys "additionalProperties" and "properties" are added, "code" key value is truncated

{
    "thoughts": [
        "t"
    ],
    "tool_args": {
        "additionalProperties": true,
        "code": "# comment line\n# comment line\n# comment line\nis_permissive = schema == {'type': 'object'",
        "properties": {},
        "runtime": "terminal"
    },
    "tool_name": "x"
}

Expected behavior

Extra garbage at the end is cleared for already valid json

{
    "thoughts": [
        "t"
    ],
    "tool_args": {
        "code": "# comment line\n# comment line\n# comment line\nis_permissive = schema == {'type': 'object', 'properties': {}, 'additionalProperties': True}",
        "runtime": "terminal"
    },
    "tool_name": "x"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions