Skip to content

Support JsonNumberHandling in JsonElement & JsonNode #29152

Open
@a11e99z

Description

@a11e99z

many JSON looks like this:
{"num":"123","str":"hello"}
Number can be in quotes too

JsonElement.GetInt64() throws Exception that "we need Number but we have a String".
I am sure that in quotes we have a Number, so code (GetInt64 and others) should ignore quotes and try parse number. and only in case when cannot parse Number(invalid chars) throw some Exception

UPD
Oops! I used unclear title. better
..JsonElement should parse Numbers in qoutes

SUMMATION:

  1. GetInt64() and etc should parse Numbers(long,uint,decimal..) for String elements: ignore first and last quotes.
  2. add .AsSpan() method to JsonElement for cases when we want to do something with elements manually. we cannot access to element data and do something useful or work around with some problem (.GetString(), .ToString(), .GetRawString() - stress GC and they are not solution)

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-System.Text.JsonenhancementProduct code improvement that does NOT require public API changes/additionsjson-functionality-docMissing JSON specific functionality that needs documenting

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions