Skip to content

Bug: Type validation – Strings like "-10" are changed to int when editing #75

Open
@l2aelba

Description

@l2aelba

When <ReactJson> has this src

[
  {
   "a": "a"
   "moreNestedData": {
     "b": "abc",
     "c": "-10"
   }
  }
]

and when I add onEdit and try to edit...

"a" = working good ✅ (without validation error message)
"b" = working good ✅ (without validation error message)
"c" = validation error ❌ (edit to "-20") (this is a normal string and it should be string) (why this is error?)

So my question is how does validation work, or how to disable it ?


This is seems like the type when editing... it changing to int

Without edit:
Image

When edit:
Image

Thanks

Activity

changed the title [-]How does validation work?[/-] [+]Bug: Type validation – Strings like "-10" are changed to int when editing[/+] on May 13, 2025
Suntgr

Suntgr commented on May 24, 2025

@Suntgr
Contributor

When <ReactJson> has this src

[
{
"a": "a"
"moreNestedData": {
"b": "abc",
"c": "-10"
}
}
]
and when I add onEdit and try to edit...

"a" = working good ✅ (without validation error message) "b" = working good ✅ (without validation error message) "c" = validation error ❌ (edit to "-20") (this is a normal string and it should be string) (why this is error?)

So my question is how does validation work, or how to disable it ?

This is seems like the type when editing... it changing to int

Without edit: Image

When edit: Image

Thanks

Hi! This is actually not a bug, but a feature.
When you edit a value, react-json-view automatically detects the data type. For strings like "-10" that match number patterns, you'll see two checkmarks on the right:
Top ✅: Keep as string ("-10")
Bottom ✅: Convert to detected type (integer -10)
Simply click the top checkmark to keep it as a string, or the bottom one to convert it to a number.
This gives you flexibility to choose the data type without manually adding quotes or formatting.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @l2aelba@Suntgr

        Issue actions

          Bug: Type validation – Strings like "-10" are changed to int when editing · Issue #75 · microlinkhq/react-json-view