react-json-view icon indicating copy to clipboard operation
react-json-view copied to clipboard

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

Open l2aelba opened this issue 8 months ago • 1 comments

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

l2aelba avatar May 13 '25 07:05 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

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.

Suntgr avatar May 24 '25 09:05 Suntgr