Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support more date-time formats for JSON deserialization #85545

Closed
gregsdennis opened this issue Apr 28, 2023 · 11 comments
Closed

Support more date-time formats for JSON deserialization #85545

gregsdennis opened this issue Apr 28, 2023 · 11 comments
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation area-System.Text.Json
Milestone

Comments

@gregsdennis
Copy link
Contributor

Description

Originally reported to JsonSchema.Net here.

The report says that System.Text.Json deserialization only supports ISO 8601 date-time formats. However JSON Schema specifies that RFC 3339 formats are to be used.

Thus a problem exists when a payload that has been validated by the schema:

{
  "type": "string",
  "format": "date-time"
}

(with format validation enabled) fails to deserialize because there is a mismatch between the format required by JSON Schema and the formats supported by System.Text.Json's deserialization.

This restriction is especially odd since DateTime.Parse() supports these formats.

Reproduction Steps

Please see attached solution.

[Test]
public void Test1()
{
	var serializerOptions = new JsonSerializerOptions
	{
		WriteIndented = true,
		Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping
	};

	var jsonDate = JsonNode.Parse("\"2023-03-20 05:41:23.3881075\"");

	Console.WriteLine(jsonDate.AsJsonString());

	JsonSchema schema = new JsonSchemaBuilder()
		.Type(SchemaValueType.String)
		.Format(Formats.DateTime);

	var results = schema.Evaluate(jsonDate, new EvaluationOptions
	{
		OutputFormat = OutputFormat.List,
		RequireFormatValidation = true
	});

	Console.WriteLine(JsonSerializer.Serialize(results, serializerOptions));
	Assert.IsTrue(results.IsValid);

	var date = jsonDate.Deserialize<DateTime>(); // fails

	Console.WriteLine(date);
}

[Test]
public void DateTimeParsing()
{
	var date = DateTime.Parse("2023-03-20 05:41:23.3881075"); // works

	Console.WriteLine(date);
}

Expected behavior

Date/time deserialization is more tolerant and accepts any format that can be handled by DateTime.Parse().

Actual behavior

Date/time deserialization MUST be ISO 8601-1:2019.

Regression?

Unsure.

Known Workarounds

A custom converter should be able to handle this, but it shouldn't really be necessary.

Configuration

These tests run in .Net 6. JsonSchema.Net is .Net Standard 2.0.

Other information

Maybe serialization could be configurable.

Date-time format comparison: https://ijmacd.github.io/rfc3339-iso8601/

@ghost ghost added the untriaged New issue has not been triaged by the area owner label Apr 28, 2023
@ghost
Copy link

ghost commented Apr 28, 2023

Tagging subscribers to this area: @dotnet/area-system-text-json, @gregsdennis
See info in area-owners.md if you want to be subscribed.

Issue Details

Description

Originally reported to JsonSchema.Net here.

The report says that System.Text.Json deserialization only supports ISO 8601 date-time formats. However JSON Schema specifies that RFC 3339 formats are to be used.

Thus a problem exists when a payload that has been validated by the schema:

{
  "type": "string",
  "format": "date-time"
}

(with format validation enabled) fails to deserialize because there is a mismatch between the format required by JSON Schema and the formats supported by System.Text.Json's deserialization.

This restriction is especially odd since DateTime.Parse() supports these formats.

Reproduction Steps

Please see attached solution.

[Test]
public void Test1()
{
	var serializerOptions = new JsonSerializerOptions
	{
		WriteIndented = true,
		Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping
	};

	var jsonDate = JsonNode.Parse("\"2023-03-20 05:41:23.3881075\"");

	Console.WriteLine(jsonDate.AsJsonString());

	JsonSchema schema = new JsonSchemaBuilder()
		.Type(SchemaValueType.String)
		.Format(Formats.DateTime);

	var results = schema.Evaluate(jsonDate, new EvaluationOptions
	{
		OutputFormat = OutputFormat.List,
		RequireFormatValidation = true
	});

	Console.WriteLine(JsonSerializer.Serialize(results, serializerOptions));
	Assert.IsTrue(results.IsValid);

	var date = jsonDate.Deserialize<DateTime>(); // fails

	Console.WriteLine(date);
}

[Test]
public void DateTimeParsing()
{
	var date = DateTime.Parse("2023-03-20 05:41:23.3881075"); // works

	Console.WriteLine(date);
}

Expected behavior

Date/time deserialization is more tolerant and accepts any format that can be handled by DateTime.Parse().

Actual behavior

Date/time deserialization MUST be ISO 8601-1:2019.

Regression?

Unsure.

Known Workarounds

A custom converter should be able to handle this, but it shouldn't really be necessary.

Configuration

These tests run in .Net 6. JsonSchema.Net is .Net Standard 2.0.

Other information

Maybe serialization could be configurable.

Date-time format comparison: https://ijmacd.github.io/rfc3339-iso8601/

Author: gregsdennis
Assignees: -
Labels:

area-System.Text.Json

Milestone: -

@layomia
Copy link
Contributor

layomia commented May 25, 2023

The primitive types supported by the serializer each support only one format for consistent implementation simplicity and to encourage the design of type/data models that would yield better performance during (de)serialization routines.

Here are a few similar issues that we've closed following this principle - https://github.com/dotnet/runtime/issues?q=is%3Aissue+label%3Aarea-System.Text.Json+formats+is%3Aclosed. As you note, a custom converter can handle this.

@layomia layomia added needs-author-action An issue or pull request that requires more info or actions from the author. and removed untriaged New issue has not been triaged by the area owner labels May 25, 2023
@ghost
Copy link

ghost commented May 25, 2023

This issue has been marked needs-author-action and may be missing some important information.

@gregsdennis
Copy link
Contributor Author

gregsdennis commented May 26, 2023

The primitive types supported by the serializer each support only one format for consistent implementation simplicity and to encourage the design of type/data models that would yield better performance during (de)serialization routines.

I completely agree that this needs to be a goal, and serializing to specific formats can help accomplish this.

However, we need to be tolerant in what we accept. (Ref: Postel's Law / Robustness Principle).

I suggest that the deserializer expect the strict format, and, if that fails, allow other formats.

Maybe this can be hidden behind a serialization option, but it should definitely be supported.

@ghost ghost added needs-further-triage Issue has been initially triaged, but needs deeper consideration or reconsideration and removed needs-author-action An issue or pull request that requires more info or actions from the author. labels May 26, 2023
@eiriktsarpalis
Copy link
Member

However, we need to be tolerant in what we accept. (Ref: Postel's Law / Robustness Principle).

I suggest that the deserializer expect the strict format, and, if that fails, allow other formats.

I think that's reasonable provided that we don't compromise the fast path.

@layomia
Copy link
Contributor

layomia commented May 26, 2023

I suggest that any such feature be opt-in to avoid breaking people who expect/depend on the strict ISO representation. Perhaps a public converter like what we have in JsonMetadataServices, but not something like JsonNumberHandling which somewhat taints the generic nature of the JsonConverter system.

@jeffhandley
Copy link
Member

I like that idea, @layomia. Something that can be optionally composed in is a good idea, with the converter's behavior being standalone.

@eiriktsarpalis eiriktsarpalis added this to the Future milestone May 29, 2023
@eiriktsarpalis eiriktsarpalis added api-suggestion Early API idea and discussion, it is NOT ready for implementation and removed needs-further-triage Issue has been initially triaged, but needs deeper consideration or reconsideration labels May 29, 2023
@gregsdennis
Copy link
Contributor Author

I suggest that any such feature be opt-in to avoid breaking people who expect/depend on the strict ISO representation.

I think I (and my users) would be satisfied with an option to control this.

@IJMacD
Copy link

IJMacD commented Jul 11, 2023

@gregsdennis

Date/time deserialization MUST be ISO 8601-1:2019.

You mention that only ISO 8601-1:2019 formats can be parsed; however I'm sure that you're aware it's actually only a small subset of valid ISO 8601-1:2019 DateTime values which are correctly deserialized;

"2023-07-11T09:06:42Z"                          OK
"2023-07-11T09:06:42.5Z"                        OK
"2023-07-11T09:06:42.55Z"                       OK
"2023-07-11T09:06:42.555Z"                      OK
"2023-07-11T09:06:42.555613Z"                   OK
"2023-07-11T17:06:42+08:00"                     OK
"2023-07-11T17:06:42.555+08:00"                 OK
"2023-07-11T17:06:42.555613+08:00"              OK
"2023-07-11T17:51:42+08:45"                     OK
"2023-07-11T09:06:42+00:00"                     OK
"2023-07-11T09:06:42.555+00:00"                 OK
"2023-07-11T17"                                 Fail
"2023-07-11T17,1"                               Fail
"2023-07-11T17.1"                               Fail
"2023-07-11T17:06"                              OK
"2023-07-11T17:06,7"                            Fail
"2023-07-11T17:06.7"                            Fail
"2023-07-11T17:06:42"                           OK
"2023-07-11T17:06:42.5"                         OK
"2023-07-11T17:06:42.55"                        OK
"2023-07-11T17:06:42,555"                       Fail
"2023-07-11T17:06:42.555"                       OK
"2023-07-11T17:06:42,555613"                    Fail
"2023-07-11T17:06:42.555613"                    OK
"2023-07-11T09Z"                                Fail
"2023-07-11T09,1Z"                              Fail
"2023-07-11T09.1Z"                              Fail
"2023-07-11T09:06Z"                             OK
"2023-07-11T09:06,7Z"                           Fail
"2023-07-11T09:06.7Z"                           Fail
"2023-07-11T09:06:42,555Z"                      Fail
"2023-07-11T09:06:42,555613Z"                   Fail
"2023-07-11T17+08"                              Fail
"2023-07-11T17,1+08"                            Fail
"2023-07-11T17.1+08"                            Fail
"2023-07-11T17:06+08"                           OK
"2023-07-11T17:06,7+08"                         Fail
"2023-07-11T17:06.7+08"                         Fail
"2023-07-11T17:06:42+08"                        OK
"2023-07-11T17:06:42.5+08"                      OK
"2023-07-11T17:06:42.55+08"                     OK
"2023-07-11T17:06:42,555+08"                    Fail
"2023-07-11T17:06:42.555+08"                    OK
"2023-07-11T17:06:42,555613+08"                 Fail
"2023-07-11T17:06:42.555613+08"                 OK
"2023-07-11T17+08:00"                           Fail
"2023-07-11T17,1+08:00"                         Fail
"2023-07-11T17.1+08:00"                         Fail
"2023-07-11T17:06+08:00"                        OK
"2023-07-11T17:06,7+08:00"                      Fail
"2023-07-11T17:06.7+08:00"                      Fail
"2023-07-11T17:06:42.5+08:00"                   OK
"2023-07-11T17:06:42.55+08:00"                  OK
"2023-07-11T17:06:42,555+08:00"                 Fail
"2023-07-11T17:06:42,555613+08:00"              Fail
"2023-W28-2T17"                                 Fail
"2023-W28-2T17,1"                               Fail
"2023-W28-2T17.1"                               Fail
"2023-W28-2T17:06"                              Fail
"2023-W28-2T17:06,7"                            Fail
"2023-W28-2T17:06.7"                            Fail
"2023-W28-2T17:06:42"                           Fail
"2023-W28-2T17:06:42.5"                         Fail
"2023-W28-2T17:06:42.55"                        Fail
"2023-W28-2T17:06:42,555"                       Fail
"2023-W28-2T17:06:42.555"                       Fail
"2023-W28-2T17:06:42,555613"                    Fail
"2023-W28-2T17:06:42.555613"                    Fail
"2023-W28-2T09Z"                                Fail
"2023-W28-2T09,1Z"                              Fail
"2023-W28-2T09.1Z"                              Fail
"2023-W28-2T09:06Z"                             Fail
"2023-W28-2T09:06,7Z"                           Fail
"2023-W28-2T09:06.7Z"                           Fail
"2023-W28-2T09:06:42Z"                          Fail
"2023-W28-2T09:06:42.5Z"                        Fail
"2023-W28-2T09:06:42.55Z"                       Fail
"2023-W28-2T09:06:42,555Z"                      Fail
"2023-W28-2T09:06:42.555Z"                      Fail
"2023-W28-2T09:06:42,555613Z"                   Fail
"2023-W28-2T09:06:42.555613Z"                   Fail
"2023-W28-2T17+08"                              Fail
"2023-W28-2T17,1+08"                            Fail
"2023-W28-2T17.1+08"                            Fail
"2023-W28-2T17:06+08"                           Fail
"2023-W28-2T17:06,7+08"                         Fail
"2023-W28-2T17:06.7+08"                         Fail
"2023-W28-2T17:06:42+08"                        Fail
"2023-W28-2T17:06:42.5+08"                      Fail
"2023-W28-2T17:06:42.55+08"                     Fail
"2023-W28-2T17:06:42,555+08"                    Fail
"2023-W28-2T17:06:42.555+08"                    Fail
"2023-W28-2T17:06:42,555613+08"                 Fail
"2023-W28-2T17:06:42.555613+08"                 Fail
"2023-W28-2T17+08:00"                           Fail
"2023-W28-2T17,1+08:00"                         Fail
"2023-W28-2T17.1+08:00"                         Fail
"2023-W28-2T17:06+08:00"                        Fail
"2023-W28-2T17:06,7+08:00"                      Fail
"2023-W28-2T17:06.7+08:00"                      Fail
"2023-W28-2T17:06:42+08:00"                     Fail
"2023-W28-2T17:06:42.5+08:00"                   Fail
"2023-W28-2T17:06:42.55+08:00"                  Fail
"2023-W28-2T17:06:42,555+08:00"                 Fail
"2023-W28-2T17:06:42.555+08:00"                 Fail
"2023-W28-2T17:06:42,555613+08:00"              Fail
"2023-W28-2T17:06:42.555613+08:00"              Fail
"2023-192T17"                                   Fail
"2023-192T17,1"                                 Fail
"2023-192T17.1"                                 Fail
"2023-192T17:06"                                Fail
"2023-192T17:06,7"                              Fail
"2023-192T17:06.7"                              Fail
"2023-192T17:06:42"                             Fail
"2023-192T17:06:42.5"                           Fail
"2023-192T17:06:42.55"                          Fail
"2023-192T17:06:42,555"                         Fail
"2023-192T17:06:42.555"                         Fail
"2023-192T17:06:42,555613"                      Fail
"2023-192T17:06:42.555613"                      Fail
"2023-192T09Z"                                  Fail
"2023-192T09,1Z"                                Fail
"2023-192T09.1Z"                                Fail
"2023-192T09:06Z"                               Fail
"2023-192T09:06,7Z"                             Fail
"2023-192T09:06.7Z"                             Fail
"2023-192T09:06:42Z"                            Fail
"2023-192T09:06:42.5Z"                          Fail
"2023-192T09:06:42.55Z"                         Fail
"2023-192T09:06:42,555Z"                        Fail
"2023-192T09:06:42.555Z"                        Fail
"2023-192T09:06:42,555613Z"                     Fail
"2023-192T09:06:42.555613Z"                     Fail
"2023-192T17+08"                                Fail
"2023-192T17,1+08"                              Fail
"2023-192T17.1+08"                              Fail
"2023-192T17:06+08"                             Fail
"2023-192T17:06,7+08"                           Fail
"2023-192T17:06.7+08"                           Fail
"2023-192T17:06:42+08"                          Fail
"2023-192T17:06:42.5+08"                        Fail
"2023-192T17:06:42.55+08"                       Fail
"2023-192T17:06:42,555+08"                      Fail
"2023-192T17:06:42.555+08"                      Fail
"2023-192T17:06:42,555613+08"                   Fail
"2023-192T17:06:42.555613+08"                   Fail
"2023-192T17+08:00"                             Fail
"2023-192T17,1+08:00"                           Fail
"2023-192T17.1+08:00"                           Fail
"2023-192T17:06+08:00"                          Fail
"2023-192T17:06,7+08:00"                        Fail
"2023-192T17:06.7+08:00"                        Fail
"2023-192T17:06:42+08:00"                       Fail
"2023-192T17:06:42.5+08:00"                     Fail
"2023-192T17:06:42.55+08:00"                    Fail
"2023-192T17:06:42,555+08:00"                   Fail
"2023-192T17:06:42.555+08:00"                   Fail
"2023-192T17:06:42,555613+08:00"                Fail
"2023-192T17:06:42.555613+08:00"                Fail
"20230711T17"                                   Fail
"20230711T17,1"                                 Fail
"20230711T17.1"                                 Fail
"20230711T1706"                                 Fail
"20230711T1706,7"                               Fail
"20230711T1706.7"                               Fail
"20230711T170642"                               Fail
"20230711T170642.5"                             Fail
"20230711T170642.55"                            Fail
"20230711T170642,555"                           Fail
"20230711T170642.555"                           Fail
"20230711T170642,555613"                        Fail
"20230711T170642.555613"                        Fail
"20230711T09Z"                                  Fail
"20230711T09,1Z"                                Fail
"20230711T09.1Z"                                Fail
"20230711T0906Z"                                Fail
"20230711T0906,7Z"                              Fail
"20230711T0906.7Z"                              Fail
"20230711T090642Z"                              Fail
"20230711T090642.5Z"                            Fail
"20230711T090642.55Z"                           Fail
"20230711T090642,555Z"                          Fail
"20230711T090642.555Z"                          Fail
"20230711T090642,555613Z"                       Fail
"20230711T090642.555613Z"                       Fail
"20230711T17+08"                                Fail
"20230711T17,1+08"                              Fail
"20230711T17.1+08"                              Fail
"20230711T1706+08"                              Fail
"20230711T1706,7+08"                            Fail
"20230711T1706.7+08"                            Fail
"20230711T170642+08"                            Fail
"20230711T170642.5+08"                          Fail
"20230711T170642.55+08"                         Fail
"20230711T170642,555+08"                        Fail
"20230711T170642.555+08"                        Fail
"20230711T170642,555613+08"                     Fail
"20230711T170642.555613+08"                     Fail
"20230711T17+0800"                              Fail
"20230711T17,1+0800"                            Fail
"20230711T17.1+0800"                            Fail
"20230711T1706+0800"                            Fail
"20230711T1706,7+0800"                          Fail
"20230711T1706.7+0800"                          Fail
"20230711T170642+0800"                          Fail
"20230711T170642.5+0800"                        Fail
"20230711T170642.55+0800"                       Fail
"20230711T170642,555+0800"                      Fail
"20230711T170642.555+0800"                      Fail
"20230711T170642,555613+0800"                   Fail
"20230711T170642.555613+0800"                   Fail
"2023W282T17"                                   Fail
"2023W282T17,1"                                 Fail
"2023W282T17.1"                                 Fail
"2023W282T1706"                                 Fail
"2023W282T1706,7"                               Fail
"2023W282T1706.7"                               Fail
"2023W282T170642"                               Fail
"2023W282T170642.5"                             Fail
"2023W282T170642.55"                            Fail
"2023W282T170642,555"                           Fail
"2023W282T170642.555"                           Fail
"2023W282T170642,555613"                        Fail
"2023W282T170642.555613"                        Fail
"2023W282T09Z"                                  Fail
"2023W282T09,1Z"                                Fail
"2023W282T09.1Z"                                Fail
"2023W282T0906Z"                                Fail
"2023W282T0906,7Z"                              Fail
"2023W282T0906.7Z"                              Fail
"2023W282T090642Z"                              Fail
"2023W282T090642.5Z"                            Fail
"2023W282T090642.55Z"                           Fail
"2023W282T090642,555Z"                          Fail
"2023W282T090642.555Z"                          Fail
"2023W282T090642,555613Z"                       Fail
"2023W282T090642.555613Z"                       Fail
"2023W282T17+08"                                Fail
"2023W282T17,1+08"                              Fail
"2023W282T17.1+08"                              Fail
"2023W282T1706+08"                              Fail
"2023W282T1706,7+08"                            Fail
"2023W282T1706.7+08"                            Fail
"2023W282T170642+08"                            Fail
"2023W282T170642.5+08"                          Fail
"2023W282T170642.55+08"                         Fail
"2023W282T170642,555+08"                        Fail
"2023W282T170642.555+08"                        Fail
"2023W282T170642,555613+08"                     Fail
"2023W282T170642.555613+08"                     Fail
"2023W282T17+0800"                              Fail
"2023W282T17,1+0800"                            Fail
"2023W282T17.1+0800"                            Fail
"2023W282T1706+0800"                            Fail
"2023W282T1706,7+0800"                          Fail
"2023W282T1706.7+0800"                          Fail
"2023W282T170642+0800"                          Fail
"2023W282T170642.5+0800"                        Fail
"2023W282T170642.55+0800"                       Fail
"2023W282T170642,555+0800"                      Fail
"2023W282T170642.555+0800"                      Fail
"2023W282T170642,555613+0800"                   Fail
"2023W282T170642.555613+0800"                   Fail
"2023192T17"                                    Fail
"2023192T17,1"                                  Fail
"2023192T17.1"                                  Fail
"2023192T1706"                                  Fail
"2023192T1706,7"                                Fail
"2023192T1706.7"                                Fail
"2023192T170642"                                Fail
"2023192T170642.5"                              Fail
"2023192T170642.55"                             Fail
"2023192T170642,555"                            Fail
"2023192T170642.555"                            Fail
"2023192T170642,555613"                         Fail
"2023192T170642.555613"                         Fail
"2023192T09Z"                                   Fail
"2023192T09,1Z"                                 Fail
"2023192T09.1Z"                                 Fail
"2023192T0906Z"                                 Fail
"2023192T0906,7Z"                               Fail
"2023192T0906.7Z"                               Fail
"2023192T090642Z"                               Fail
"2023192T090642.5Z"                             Fail
"2023192T090642.55Z"                            Fail
"2023192T090642,555Z"                           Fail
"2023192T090642.555Z"                           Fail
"2023192T090642,555613Z"                        Fail
"2023192T090642.555613Z"                        Fail
"2023192T17+08"                                 Fail
"2023192T17,1+08"                               Fail
"2023192T17.1+08"                               Fail
"2023192T1706+08"                               Fail
"2023192T1706,7+08"                             Fail
"2023192T1706.7+08"                             Fail
"2023192T170642+08"                             Fail
"2023192T170642.5+08"                           Fail
"2023192T170642.55+08"                          Fail
"2023192T170642,555+08"                         Fail
"2023192T170642.555+08"                         Fail
"2023192T170642,555613+08"                      Fail
"2023192T170642.555613+08"                      Fail
"2023192T17+0800"                               Fail
"2023192T17,1+0800"                             Fail
"2023192T17.1+0800"                             Fail
"2023192T1706+0800"                             Fail
"2023192T1706,7+0800"                           Fail
"2023192T1706.7+0800"                           Fail
"2023192T170642+0800"                           Fail
"2023192T170642.5+0800"                         Fail
"2023192T170642.55+0800"                        Fail
"2023192T170642,555+0800"                       Fail
"2023192T170642.555+0800"                       Fail
"2023192T170642,555613+0800"                    Fail
"2023192T170642.555613+0800"                    Fail
"2023\u201007\u201011T09:06:42Z"                Fail
"2023-07-11T17:06:42+08"                        OK
"2023-07-10T21-12"                              Fail
"2023-07-10T21-12:00"                           Fail
"2023-07-10T21:06-12"                           OK
"2023-07-10T21:06-12:00"                        OK
"2023-07-10T21:06:42\u221212"                   Fail
"2023-07-10T21:06:42\u221212:00"                Fail

As a comparison here are the RFC 3339 formats which can currently correctly be deserialized.

"2023-07-11T09:13:56.5Z"                        OK
"2023-07-11T09:13:56.55Z"                       OK
"2023-07-11T09:13:56.555Z"                      OK
"2023-07-11T09:13:56.555613Z"                   OK
"2023-07-11t09:13:56z"                          Fail
"2023-07-11t09:13:56.555z"                      Fail
"2023-07-11T17:13:56+08:00"                     OK
"2023-07-11T17:13:56.555+08:00"                 OK
"2023-07-11T17:13:56.555613+08:00"              OK
"2023-07-11 17:13:56+08:00"                     Fail
"2023-07-11 17:13:56.5+08:00"                   Fail
"2023-07-11 17:13:56.55+08:00"                  Fail
"2023-07-11 17:13:56.555+08:00"                 Fail
"2023-07-11 17:13:56.555613+08:00"              Fail
"2023-07-11 09:13:56Z"                          Fail
"2023-07-11_09:13:56Z"                          Fail
"2023-07-11 09:13:56z"                          Fail
"2023-07-11_09:13:56z"                          Fail
"2023-07-11 09:13:56.5Z"                        Fail
"2023-07-11 09:13:56.55Z"                       Fail
"2023-07-11 09:13:56.555Z"                      Fail
"2023-07-11_09:13:56.555Z"                      Fail
"2023-07-11 09:13:56.555613Z"                   Fail
"2023-07-11_09:13:56.555613Z"                   Fail
"2023-07-11 09:13:56.555z"                      Fail
"2023-07-11_09:13:56.555z"                      Fail
"2023-07-11 09:13:56.555613z"                   Fail
"2023-07-11_09:13:56.555613z"                   Fail
"2023-07-11 09:13:56-00:00"                     Fail
"2023-07-11 09:13:56.555-00:00"                 Fail
"2023-07-11T09:13:56-00:00"                     OK
"2023-07-11T09:13:56.555-00:00"                 OK
"2023-07-11T17:58:56+08:45"                     OK
"2023-07-11T09:13:56+00:00"                     OK
"2023-07-11T09:13:56.555+00:00"                 OK

To be clear, I'm not suggesting supporting all valid formats is necessarily a priority; but explicitness (along with Postel's Law) is usually an excellent start.

@gregsdennis
Copy link
Contributor Author

Thanks, @IJMacD! That's very thorough. From that, it looks like only the following formats are supported by both .Net and JSON Schema.

"2023-07-11T09:06:42.5Z"
"2023-07-11T09:06:42.55Z"
"2023-07-11T09:06:42.555Z"
"2023-07-11T09:06:42.555613Z"
"2023-07-11T17:06:42+08:00"
"2023-07-11T17:06:42.555+08:00"
"2023-07-11T17:06:42.555613+08:00"
"2023-07-11T09:06:42+00:00"
"2023-07-11T09:06:42.555+00:00"

This is good info to have documented!

@gregsdennis
Copy link
Contributor Author

I think I'm happy with having this documented. Thanks!

@ghost ghost locked as resolved and limited conversation to collaborators Aug 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation area-System.Text.Json
Projects
None yet
Development

No branches or pull requests

5 participants