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

"[]".AsJsonElement() will not return as array. It will return as a string #51

Closed
NanFengCheong opened this issue Dec 10, 2020 · 2 comments
Labels
not-a-bug A reported issue is actually working as designed pkg:more

Comments

@NanFengCheong
Copy link

NanFengCheong commented Dec 10, 2020

Describe the bug
"[]".AsJsonElement() will not return as array. It will return as a string;

To Reproduce
"[]".AsJsonElement() != JsonDocument.Parse("[]").RootElement

Expected behavior
A clear and concise description of what you expected to happen.
It should be a json array

Desktop (please complete the following information):

  • OS: [e.g. iOS] windows 10
  • .Net Target (Fwk 4.8, Core 3.x, etc.) 5.x
@gregsdennis
Copy link
Owner

gregsdennis commented Dec 11, 2020

That's because you're giving the method a string. This method and its overrides take objects and give the JsonElement equivalent of the object. It is not a shortcut for parsing or deserialization.

To get an empty array, use new JsonElement[].ToJsonElement(). This will give a single element containing an empty JSON array.

@gregsdennis gregsdennis added not-a-bug A reported issue is actually working as designed pkg:more labels Dec 11, 2020
@NanFengCheong
Copy link
Author

Got it. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
not-a-bug A reported issue is actually working as designed pkg:more
Projects
None yet
Development

No branches or pull requests

2 participants