Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
db7bdad
initial draft
tdykstra Nov 27, 2019
c9e7a21
fix links
tdykstra Dec 12, 2019
88cd245
fix link
tdykstra Dec 13, 2019
0f60978
corrections
tdykstra Dec 13, 2019
3c634dc
add new doc to toc
tdykstra Dec 13, 2019
d994f56
add'l notes from ahson email
tdykstra Dec 13, 2019
6d4216c
fix issue numbers
tdykstra Dec 13, 2019
2594e49
comment out roadmap link
tdykstra Dec 13, 2019
823b581
incorporate info from roadmap
tdykstra Dec 15, 2019
7dd85d6
more info from roadmap
tdykstra Dec 15, 2019
3a2ab3d
address thraka feedback
tdykstra Dec 17, 2019
c546273
Newtonsoft --> Json.NET
tdykstra Dec 17, 2019
07cc159
omit 'the current release of'
tdykstra Dec 17, 2019
20f1095
omit 'by design'
tdykstra Dec 17, 2019
41019bc
link to exact hash instead of branch
tdykstra Dec 17, 2019
0665118
Json.NET --> Newtonsoft.Json
tdykstra Dec 17, 2019
7243deb
scrub additional resources sections
tdykstra Dec 17, 2019
163ed4e
rearrange several h2 sections
tdykstra Dec 17, 2019
b5bd3e7
add (marshal/unmarshal) to headings
tdykstra Dec 19, 2019
7771245
update dates
tdykstra Dec 20, 2019
a1eae47
ahson feedback, restore code to converters doc
tdykstra Dec 24, 2019
b023d84
move 3 converters back to converter doc
tdykstra Dec 24, 2019
55d99cc
additional note from comments in 36639
tdykstra Dec 24, 2019
a78c5ac
minor clarification
tdykstra Dec 26, 2019
9c331ff
remove links to issues
tdykstra Dec 27, 2019
618aca8
add links to s.t.j.serialization
tdykstra Dec 27, 2019
84a65bc
remove extraneous words
tdykstra Dec 27, 2019
e4a27a1
remove extraneous words
tdykstra Dec 27, 2019
6b279eb
4.6.1 --> 4.7.2
tdykstra Dec 27, 2019
2feef06
Update docs/standard/serialization/system-text-json-converters-how-to.md
tdykstra Dec 27, 2019
99619d1
ahson feedback section 1
tdykstra Dec 27, 2019
ec3d07c
fix h2->h3, tweak heading text
tdykstra Dec 27, 2019
1919f9d
layomi feedback
tdykstra Dec 27, 2019
0f9a494
reapply change lost earlier
tdykstra Dec 27, 2019
16b73b3
remove dbnull comments
tdykstra Dec 28, 2019
4618b0c
Apply suggestions from code review
tdykstra Dec 31, 2019
1bcb4f3
Apply suggestion from code review
tdykstra Dec 31, 2019
66dbd62
ahson feedback
tdykstra Dec 31, 2019
805f425
Merge branch 'jnmigrate' of https://github.com/tdykstra/dotnet-docs i…
tdykstra Dec 31, 2019
6fc6377
make registration links more specific
tdykstra Dec 31, 2019
57fb760
add converters api link
tdykstra Jan 1, 2020
35434dd
Apply suggestions from code review
tdykstra Jan 1, 2020
93d7564
add note to null-to-nonnullable section
tdykstra Jan 1, 2020
2610c4a
Update docs/standard/serialization/system-text-json-migrate-from-newt…
tdykstra Jan 1, 2020
957f976
Apply suggestions from code review
tdykstra Jan 1, 2020
9fc486a
fix link
tdykstra Jan 1, 2020
bc30ca2
acrolinx and feedback
tdykstra Jan 1, 2020
9a057bb
add workaround notes
tdykstra Jan 1, 2020
93194b2
first occurrrences of STJ --> xref link
tdykstra Jan 6, 2020
2273cf4
more api ref links
tdykstra Jan 6, 2020
1c34eb5
Merge branch 'master' into jnmigrate
tdykstra Jan 6, 2020
0890e2e
strings in quotes, nonstring values, polymorphism
tdykstra Jan 7, 2020
5a0b857
corrections to polymorphic sections
tdykstra Jan 7, 2020
b721d7b
address feedback
tdykstra Jan 7, 2020
f6b0a55
more feedback
tdykstra Jan 7, 2020
26930e8
minor wording change
tdykstra Jan 7, 2020
b68ba5e
misc feedback
tdykstra Jan 8, 2020
80ed897
misc feedback
tdykstra Jan 8, 2020
c2191e6
revise polymorphic interface example
tdykstra Jan 8, 2020
43a657a
misc feedback
tdykstra Jan 8, 2020
7b53d91
fix links
tdykstra Jan 8, 2020
fd05648
standardize links to source code
tdykstra Jan 8, 2020
303d8e5
shorten valuetextequals example
tdykstra Jan 8, 2020
63e02ab
misc feedback
tdykstra Jan 8, 2020
65be137
misc feedback
tdykstra Jan 9, 2020
72a8a34
valuetuple
tdykstra Jan 10, 2020
50b3574
invitation to share workaround code
tdykstra Jan 10, 2020
fd61261
feedback
tdykstra Jan 10, 2020
942e7c2
proofread pass
tdykstra Jan 10, 2020
f6d6623
update ms.date
tdykstra Jan 10, 2020
2fa28ee
tools --> APIs
tdykstra Jan 10, 2020
27d4fd4
feedback
tdykstra Jan 10, 2020
55ee7b7
immutablestack
tdykstra Jan 10, 2020
b3eb4f4
clarify when to clone
tdykstra Jan 10, 2020
2470d9e
revert change already made by 16615
tdykstra Jan 11, 2020
30277d7
Update docs/standard/serialization/system-text-json-migrate-from-newt…
tdykstra Jan 11, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feedback
  • Loading branch information
tdykstra committed Jan 10, 2020
commit fd6126114bf938d35212de4695872f66cb846408
Original file line number Diff line number Diff line change
Expand Up @@ -520,11 +520,13 @@ The following sections explain recommended programming patterns for using `Utf8J

### Write with UTF-8 text

To achieve the best possible performance while using the `Utf8JsonWriter`, write JSON payloads already encoded as UTF-8 text rather than as UTF-16 strings. For example, if you're writing string literals, consider caching them as static byte arrays, and write those instead.
To achieve the best possible performance while using the `Utf8JsonWriter`, write JSON payloads already encoded as UTF-8 text rather than as UTF-16 strings. Use <xref:System.Text.Json.JsonEncodedText> to cache and pre-encode known string property names and values as statics, and pass those to the writer, rather than using UTF-16 string literals. This is faster than caching and using UTF-8 byte arrays.

This approach also works if you need to do custom escaping. `System.Text.Json` doesn't let you disable escaping while writing a string. However, you could pass in your own custom <xref:System.Text.Encodings.Web.JavaScriptEncoder> as an option to the writer, or create your own `JsonEncodedText` which uses your `JavascriptEncoder` do to the escaping and then write the `JsonEncodedText` instead of the string. For more information, see [Customize character encoding](system-text-json-how-to.md#customize-character-encoding).

### Write raw values

The `Newtonsoft.Json` `WriteRawValue` method writes raw JSON where a value is expected. <xref:System.Text.Json> has no direct equivalent, but here's a workaround:
The `Newtonsoft.Json` `WriteRawValue` method writes raw JSON where a value is expected. <xref:System.Text.Json> has no direct equivalent, but here's a workaround that ensures only valid JSON is written:

```csharp
using JsonDocument doc = JsonDocument.Parse(string);
Expand All @@ -533,16 +535,16 @@ doc.WriteTo(writer);

Copy link
Contributor

@ahsonkhan ahsonkhan Jan 7, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't provide equivalent of granular WriteXAsync APIs on the Utf8JsonWriter. The guideline/pattern we encourage is doing a bunch of synchronous writes, and then periodically call FlushAsync. A section on that would be useful (but let's defer that for now). I can flesh that out a bit more, if needed.

I don't think a lot of people use the WriteXAsync APIs on JsonWriter from Newtonsoft.Json anyway. I saw zero hits on apisof.net for folks using the WriteXAsync APIs.

### Customize character escaping

The [StringEscapeHandling](https://www.newtonsoft.com/json/help/html/T_Newtonsoft_Json_StringEscapeHandling.htm) setting of `JsonTextWriter` offers options to escape all non-ASCII characters **or** HTML characters. By default, Utf8JsonWriter escapes all non-ASCII **and** HTML characters. This escaping is done for defense-in-depth security reasons. To specify a different escaping policy, create a <xref:System.Text.Encodings.Web.JavaScriptEncoder> and set <xref:System.Text.Json.JsonWriterOptions.Encoder?displayProperty=nameWithType>. For more information, see [Customize character encoding](system-text-json-how-to.md#customize-character-encoding).
The [StringEscapeHandling](https://www.newtonsoft.com/json/help/html/T_Newtonsoft_Json_StringEscapeHandling.htm) setting of `JsonTextWriter` offers options to escape all non-ASCII characters **or** HTML characters. By default, `Utf8JsonWriter` escapes all non-ASCII **and** HTML characters. This escaping is done for defense-in-depth security reasons. To specify a different escaping policy, create a <xref:System.Text.Encodings.Web.JavaScriptEncoder> and set <xref:System.Text.Json.JsonWriterOptions.Encoder?displayProperty=nameWithType>. For more information, see [Customize character encoding](system-text-json-how-to.md#customize-character-encoding).

### Customize JSON format

`JsonTextWriter` includes the following settings, for which `Utf8JsonWriter` has no equivalent:

* [Indentation](https://www.newtonsoft.com/json/help/html/P_Newtonsoft_Json_JsonTextWriter_Indentation.htm) - How many characters to indent. `Utf8JsonWriter` always does 2-character indentation.
[IndentChar](https://www.newtonsoft.com/json/help/html/P_Newtonsoft_Json_JsonTextWriter_IndentChar.htm) - What character to use for indentation. `Utf8JsonWriter` always uses whitespace.
[QuoteChar](https://www.newtonsoft.com/json/help/html/P_Newtonsoft_Json_JsonTextWriter_QuoteChar.htm) - What character to use to surround string values. `Utf8JsonWriter` always uses double quotes.
[QuoteName](https://www.newtonsoft.com/json/help/html/P_Newtonsoft_Json_JsonTextWriter_QuoteName.htm) - Whether or not to surround property names with quotes. `Utf8JsonWriter` always uses quotes.
* [Indentation](https://www.newtonsoft.com/json/help/html/P_Newtonsoft_Json_JsonTextWriter_Indentation.htm) - Specifies how many characters to indent. `Utf8JsonWriter` always does 2-character indentation.
* [IndentChar](https://www.newtonsoft.com/json/help/html/P_Newtonsoft_Json_JsonTextWriter_IndentChar.htm) - Specifies the character to use for indentation. `Utf8JsonWriter` always uses whitespace.
* [QuoteChar](https://www.newtonsoft.com/json/help/html/P_Newtonsoft_Json_JsonTextWriter_QuoteChar.htm) - Specifies the character to use to surround string values. `Utf8JsonWriter` always uses double quotes.
* [QuoteName](https://www.newtonsoft.com/json/help/html/P_Newtonsoft_Json_JsonTextWriter_QuoteName.htm) - Specifies whether or not to surround property names with quotes. `Utf8JsonWriter` always surrounds them with quotes.

There are no workarounds that would let you customize the JSON produced by `Utf8JsonWriter` in these ways.

Expand Down