Skip to content

System.Text.Json serializing null becomes "null" as 'serialized' object #101420

Closed Answered by huoyaoyuan
Fazer01 asked this question in Q&A
Discussion options

You must be logged in to vote

The behavior is correct. null is a valid top-level JSON value. Trying in browser console you will get:

> JSON.stringify(null)
'null'
> JSON.parse('null')
null

That's why the return value of JsonSerializer.Parse<T> is always nullable, since there's top-level "null" literal. See also #100144 (comment)

Replies: 3 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@Fazer01
Comment options

Answer selected by Fazer01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
area-System.Text.Json untriaged New issue has not been triaged by the area owner
2 participants
Converted from issue

This discussion was converted from issue #101419 on April 23, 2024 08:45.