josdejong / jsoneditor

A web-based tool to view, edit, format, and validate JSON
http://jsoneditoronline.org
Apache License 2.0
11.65k stars 2.04k forks source link

Inconsistent validation for string type fields. #1541

Open incy-tron opened 1 year ago

incy-tron commented 1 year ago

I have multiple fields where the type is defined as: [string, null] some fields will allow a integer value whereas other will show a warning. For example, I have two fields defined as:

    {"title":"Os Minorversion","type":["string","null"]}
    {"title":"Os Version","type":["string","null"]}

Os Version doesn't show a warning when entering an integer, however, Os Minorversion will.

I'm using jsoneditor v9.10.2 within an Angular v14.3.0 project.

I've tried rolling back all the way to jsoneditor v9.7.4, but this issue still persists.

josdejong commented 1 year ago

In your screenshot, os_minorversion has a number 5 as value (colored red), and os_version is a string with value "7" (colored green). You can change between number/string via the context menu, type, auto or string.

incy-tron commented 1 year ago

Thanks for the prompt reply!

Ok. It was set to Auto, is there a way for me through the API to automatically set that? I don't want users to have to worry about.

Steig


From: Jos de Jong @.> Sent: Thursday, July 27, 2023 12:07 PM To: josdejong/jsoneditor @.> Cc: Hallquist, Steig @.>; Author @.> Subject: [External] - Re: [josdejong/jsoneditor] Inconsistent validation for string type fields. (Issue #1541)

CAUTION: External email.


In your screenshot, os_minorversion has a number 5 as value (colored red), and os_version is a string with value "7" (colored green). You can change between number/string via the context menu, type, auto or string.

— Reply to this email directly, view it on GitHubhttps://github.com/josdejong/jsoneditor/issues/1541#issuecomment-1653919721, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AU6OD4R6SN6WGW6T6YICL23XSKG25ANCNFSM6AAAAAA22CFC2Y. You are receiving this because you authored the thread.Message ID: @.***>

This communication, including any attachments, may contain Proprietary, Export Controlled, Legally Privileged or other Confidential Information. Any unauthorized review, printing, copying, transmission, dissemination, or use of the information is strictly prohibited. If you are not the intended recipient, please indicate to the sender that you have received this email in error, and delete the copy you received.

josdejong commented 1 year ago

It just displays what you provide it. The editor normally loads values with "auto" mode. There is only one case where it sets the value type to string and keeps it like that (until you manually change the type): when a value is a string containing a numeric value.

So if you load the following example:

{
  "os_version": "7"
}

the value of "os_version" will have type string until you manually change that.

In the following example, the type is auto:

{
  "os_version": 7
}