From e4f5c01e000193558c76f1bb619714e2a15c8992 Mon Sep 17 00:00:00 2001 From: Megha Anand <88059806+anandmeg@users.noreply.github.com> Date: Sun, 15 Sep 2024 15:52:33 -0700 Subject: [PATCH 1/8] Add Copilot use case example --- .../system-text-json/customize-properties.md | 138 ++++++++++++++++++ 1 file changed, 138 insertions(+) diff --git a/docs/standard/serialization/system-text-json/customize-properties.md b/docs/standard/serialization/system-text-json/customize-properties.md index 70c013ea7d327..d03bf7c8a0cf3 100644 --- a/docs/standard/serialization/system-text-json/customize-properties.md +++ b/docs/standard/serialization/system-text-json/customize-properties.md @@ -13,6 +13,8 @@ helpviewer_keywords: - "serialization" - "objects, serializing" ms.topic: how-to +ms.collection: ce-skilling-ai-copilot +ms.custom: vs-copilot-horizontal --- # How to customize property names and values with System.Text.Json @@ -28,6 +30,9 @@ By default, property names and dictionary keys are unchanged in the JSON output, > [!NOTE] > The [web default](configure-options.md#web-defaults-for-jsonserializeroptions) naming policy is camel case. +> [!TIP] +> You can use AI assistance to [customize property names and values with GitHub Copilot](#use-github-copilot-to-customize-property-names-and-values). + For other scenarios that require special handling of JSON property names and values, you can [implement custom converters](converters-how-to.md). ## Customize individual property names @@ -228,7 +233,140 @@ By default, properties are serialized in the order in which they're defined in t :::code language="csharp" source="snippets/how-to-6-0/csharp/PropertyOrder.cs"::: +## Use Github Copilot to customize property names and order + +You can use GitHub Copilot in your IDE to generate code to customzie names and order of serialized properties. + +If you're using [Visual Studio 2022 version 17.8 or later](/visualstudio/releases/2022/release-notes), you can try the AI-driven [GitHub Copilot in Visual Studio](/visualstudio/ide/visual-studio-github-copilot-install-and-states) to generate code that uses `System.Text.Json` to customize property names and order in the JSON output from serializtion. Submit your question as a prompt in the Copilot chat window, as in the following example. You can also submit prompts using [inline chat](/visualstudio/ide/visual-studio-github-copilot-chat#ask-questions-in-the-inline-chat-view) in the editor window itself. + +> [!NOTE] +> GitHub Copilot is powered by AI, so surprises and mistakes are possible. Make sure to verify any generated code or suggestions. For more information about the general use of GitHub Copilot, product impact, human oversight, and privacy, see [GitHub Copilot FAQs](https://github.com/features/copilot#faq). + +The following example shows you how to use Copilot to modify exisitng code to customize property names and order when serializing to JSON. + +1. Add the following C# example code to a code file `Example.cs` in your editor. + In Visual Studio, you can use a C# console application project to try this example. + + ```csharp + using System.Text.Json; + + //Create an instance of the `Person` class and initialize its properties with values. + public class Person + { + public string? FirstName { get; set; } + public string? LastName { get; set; } + public int Age { get; set; } + public string? Country { get; set; } + } + + public class Program + { + public static void Main() + { + var person = new Person + { + FirstName = "John", + LastName = "Doe", + Age = 30, + Country = "USA" + }; + + //Serialize the `person` object to a JSON string using `System.Text.Json` + string jsonString = JsonSerializer.Serialize(person); + + //Print the JSON string to the console + Console.WriteLine(jsonString); + } + } + ``` + + `Example.cs` code does the following: + - Creates an instance of the `Person` class and initializes its properties with values. + - Serializes the `person` object to a JSON string using `JsonSerializer.Serialize`. + - Prints the following JSON string to the console: + ```json + {"FirstName":"John","LastName":"Doe","Age":30,"Country":"USA"} + ``` +1. In Copilot Chat, enter the following prompt to modify the code to customize names and order of the JSON serialization output. + +> #file:'Example.cs' modify code to use System.Text.Json to customize property names and order of JSON output from serializtion. Set property names FirstName to first_name, LastName to last_name. Set order to: Country, FirstName, LastName, Age. Provide customized serialization output. + +You can customize the prompt to output a JSON string with property names and values that suit your requirements. + +You can use chat features, such as [slash commands, references to files, methods, or classes, and threads](/visualstudio/ide/copilot-chat-context), to set intent and get better answers with scoped context. For an existing class in a project that's open in the IDE, you can prompt GitHub Copilot with `/generate code to serialize #Classname in #Filename to JSON`. + +The following output shows an example Copilot Chat response: + +```output +To customize the property names and order of the JSON output using System.Text.Json, you can use the JsonPropertyName attribute to rename properties and the JsonPropertyOrder attribute to set the order. Here's how you can modify your code: + +using System.Text.Json; +using System.Text.Json.Serialization; + +public class Person +{ + [JsonPropertyName("first_name")] + [JsonPropertyOrder(2)] + public string? FirstName { get; set; } + + [JsonPropertyName("last_name")] + [JsonPropertyOrder(3)] + public string? LastName { get; set; } + + [JsonPropertyOrder(4)] + public int Age { get; set; } + + [JsonPropertyOrder(1)] + public string? Country { get; set; } +} + +public class Program +{ + public static void Main() + { + var person = new Person + { + FirstName = "John", + LastName = "Doe", + Age = 30, + Country = "USA" + }; + + string jsonString = JsonSerializer.Serialize(person, new JsonSerializerOptions { WriteIndented = true }); + Console.WriteLine(jsonString); + } +} + +**Explanation:** +1. Renaming Properties: The JsonPropertyName attribute is used to rename FirstName to first_name and LastName to last_name. +2. Ordering Properties: The JsonPropertyOrder attribute is used to set the order of the properties in the JSON output. The order is set as: + • Country (Order 1) + • FirstName (Order 2) + • LastName (Order 3) + • Age (Order 4) +3. Indented JSON: The JsonSerializerOptions with WriteIndented = true is used to make the JSON output more readable. + +**Customized Serialization Output:** +{ + "Country": "USA", + "first_name": "John", + "last_name": "Doe", + "Age": 30 +} + +This ensures that the JSON output has the customized property names and the specified order. +``` + +When Copilot returns a code block, the response includes options to copy the code, insert the code into a new file, or preview the code output. + +> [!NOTE] +> Your results might be different from what's shown in the example responses. AI models are non-deterministic, which means that they can return different responses when asked the same question. This might be due to additional learning and adaption over time, language variation, changes in context, such as your chat history, and more. +:::image type="content" source="./media/deserialize-json-using-github-copilot.gif" alt-text="Animated screenshot that shows using GitHub Copilot Chat in Visual Studio to deserialize a JSON string to a .NET object." lightbox="./media/deserialize-json-using-github-copilot.gif"::: + ## See also - [System.Text.Json overview](overview.md) - [How to serialize and deserialize JSON](how-to.md) +- [GitHub Copilot Trust Center](https://resources.github.com/copilot-trust-center/) +- [GitHub Copilot in Visual Studio](/visualstudio/ide/visual-studio-github-copilot-install-and-states) +- [GitHub Copilot in VS Code](https://code.visualstudio.com/docs/copilot/overview) From 8583e1eb6c56d78ace102183d0251e61a8402b86 Mon Sep 17 00:00:00 2001 From: Megha Anand <88059806+anandmeg@users.noreply.github.com> Date: Sun, 15 Sep 2024 16:09:56 -0700 Subject: [PATCH 2/8] Fix link --- .../serialization/system-text-json/customize-properties.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/standard/serialization/system-text-json/customize-properties.md b/docs/standard/serialization/system-text-json/customize-properties.md index d03bf7c8a0cf3..054eb3272c8b5 100644 --- a/docs/standard/serialization/system-text-json/customize-properties.md +++ b/docs/standard/serialization/system-text-json/customize-properties.md @@ -31,7 +31,7 @@ By default, property names and dictionary keys are unchanged in the JSON output, > The [web default](configure-options.md#web-defaults-for-jsonserializeroptions) naming policy is camel case. > [!TIP] -> You can use AI assistance to [customize property names and values with GitHub Copilot](#use-github-copilot-to-customize-property-names-and-values). +> You can use AI assistance to [customize property names and values with GitHub Copilot](#use-github-copilot-to-customize-property-names-and-order). For other scenarios that require special handling of JSON property names and values, you can [implement custom converters](converters-how-to.md). From 21d04ff30da005161ba2b26fbf9414a1b417f169 Mon Sep 17 00:00:00 2001 From: Megha Anand <88059806+anandmeg@users.noreply.github.com> Date: Sun, 15 Sep 2024 16:52:30 -0700 Subject: [PATCH 3/8] Fix build error --- .../serialization/system-text-json/customize-properties.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/standard/serialization/system-text-json/customize-properties.md b/docs/standard/serialization/system-text-json/customize-properties.md index 054eb3272c8b5..b02b95cbe0027 100644 --- a/docs/standard/serialization/system-text-json/customize-properties.md +++ b/docs/standard/serialization/system-text-json/customize-properties.md @@ -289,7 +289,7 @@ The following example shows you how to use Copilot to modify exisitng code to cu ``` 1. In Copilot Chat, enter the following prompt to modify the code to customize names and order of the JSON serialization output. -> #file:'Example.cs' modify code to use System.Text.Json to customize property names and order of JSON output from serializtion. Set property names FirstName to first_name, LastName to last_name. Set order to: Country, FirstName, LastName, Age. Provide customized serialization output. +> #Example.cs modify code to use System.Text.Json to customize property names and order of JSON output from serializtion. Set property names FirstName to first_name, LastName to last_name. Set order to: Country, FirstName, LastName, Age. Provide customized serialization output. You can customize the prompt to output a JSON string with property names and values that suit your requirements. From 87c11625d31e2211474f70a7ef97b12ad8071ad1 Mon Sep 17 00:00:00 2001 From: Megha Anand <88059806+anandmeg@users.noreply.github.com> Date: Sun, 15 Sep 2024 17:05:26 -0700 Subject: [PATCH 4/8] Fix steps --- .../system-text-json/customize-properties.md | 110 +++++++++--------- 1 file changed, 55 insertions(+), 55 deletions(-) diff --git a/docs/standard/serialization/system-text-json/customize-properties.md b/docs/standard/serialization/system-text-json/customize-properties.md index b02b95cbe0027..0afc0ba68058d 100644 --- a/docs/standard/serialization/system-text-json/customize-properties.md +++ b/docs/standard/serialization/system-text-json/customize-properties.md @@ -289,79 +289,79 @@ The following example shows you how to use Copilot to modify exisitng code to cu ``` 1. In Copilot Chat, enter the following prompt to modify the code to customize names and order of the JSON serialization output. -> #Example.cs modify code to use System.Text.Json to customize property names and order of JSON output from serializtion. Set property names FirstName to first_name, LastName to last_name. Set order to: Country, FirstName, LastName, Age. Provide customized serialization output. + > `#Example.cs` modify code to use `System.Text.Json` to customize property names and order of JSON output from serializtion. Set property names FirstName to first_name, LastName to last_name. Set order to: Country, FirstName, LastName, Age. Provide customized serialization output. -You can customize the prompt to output a JSON string with property names and values that suit your requirements. + You can customize the prompt to output a JSON string with property names and values that suit your requirements. -You can use chat features, such as [slash commands, references to files, methods, or classes, and threads](/visualstudio/ide/copilot-chat-context), to set intent and get better answers with scoped context. For an existing class in a project that's open in the IDE, you can prompt GitHub Copilot with `/generate code to serialize #Classname in #Filename to JSON`. + You can use chat features, such as [slash commands, references to files, methods, or classes, and threads](/visualstudio/ide/copilot-chat-context), to set intent and get better answers with scoped context. -The following output shows an example Copilot Chat response: + The following output shows an example Copilot Chat response: -```output -To customize the property names and order of the JSON output using System.Text.Json, you can use the JsonPropertyName attribute to rename properties and the JsonPropertyOrder attribute to set the order. Here's how you can modify your code: + ```output -using System.Text.Json; -using System.Text.Json.Serialization; + To customize the property names and order of the JSON output using System.Text.Json, you can use the JsonPropertyName attribute to rename properties and the JsonPropertyOrder attribute to set the order. Here's how you can modify your code: -public class Person -{ - [JsonPropertyName("first_name")] - [JsonPropertyOrder(2)] - public string? FirstName { get; set; } + using System.Text.Json; + using System.Text.Json.Serialization; - [JsonPropertyName("last_name")] - [JsonPropertyOrder(3)] - public string? LastName { get; set; } + public class Person + { + [JsonPropertyName("first_name")] + [JsonPropertyOrder(2)] + public string? FirstName { get; set; } - [JsonPropertyOrder(4)] - public int Age { get; set; } + [JsonPropertyName("last_name")] + [JsonPropertyOrder(3)] + public string? LastName { get; set; } - [JsonPropertyOrder(1)] - public string? Country { get; set; } -} + [JsonPropertyOrder(4)] + public int Age { get; set; } -public class Program -{ - public static void Main() + [JsonPropertyOrder(1)] + public string? Country { get; set; } + } + + public class Program { - var person = new Person + public static void Main() { - FirstName = "John", - LastName = "Doe", - Age = 30, - Country = "USA" - }; - - string jsonString = JsonSerializer.Serialize(person, new JsonSerializerOptions { WriteIndented = true }); - Console.WriteLine(jsonString); + var person = new Person + { + FirstName = "John", + LastName = "Doe", + Age = 30, + Country = "USA" + }; + + string jsonString = JsonSerializer.Serialize(person, new JsonSerializerOptions { WriteIndented = true }); + Console.WriteLine(jsonString); + } } -} -**Explanation:** -1. Renaming Properties: The JsonPropertyName attribute is used to rename FirstName to first_name and LastName to last_name. -2. Ordering Properties: The JsonPropertyOrder attribute is used to set the order of the properties in the JSON output. The order is set as: - • Country (Order 1) - • FirstName (Order 2) - • LastName (Order 3) - • Age (Order 4) -3. Indented JSON: The JsonSerializerOptions with WriteIndented = true is used to make the JSON output more readable. + **Explanation:** + 1. Renaming Properties: The JsonPropertyName attribute is used to rename FirstName to first_name and LastName to last_name. + 2. Ordering Properties: The JsonPropertyOrder attribute is used to set the order of the properties in the JSON output. The order is set as: + • Country (Order 1) + • FirstName (Order 2) + • LastName (Order 3) + • Age (Order 4) + 3. Indented JSON: The JsonSerializerOptions with WriteIndented = true is used to make the JSON output more readable. -**Customized Serialization Output:** -{ - "Country": "USA", - "first_name": "John", - "last_name": "Doe", - "Age": 30 -} + **Customized Serialization Output:** + { + "Country": "USA", + "first_name": "John", + "last_name": "Doe", + "Age": 30 + } -This ensures that the JSON output has the customized property names and the specified order. -``` + This ensures that the JSON output has the customized property names and the specified order. + ``` -When Copilot returns a code block, the response includes options to copy the code, insert the code into a new file, or preview the code output. + When Copilot returns a code block, the response includes options to copy the code, insert the code into a new file, or preview the code output. -> [!NOTE] -> Your results might be different from what's shown in the example responses. AI models are non-deterministic, which means that they can return different responses when asked the same question. This might be due to additional learning and adaption over time, language variation, changes in context, such as your chat history, and more. -:::image type="content" source="./media/deserialize-json-using-github-copilot.gif" alt-text="Animated screenshot that shows using GitHub Copilot Chat in Visual Studio to deserialize a JSON string to a .NET object." lightbox="./media/deserialize-json-using-github-copilot.gif"::: + > [!NOTE] + > Your results might be different from what's shown in the example responses. AI models are non-deterministic, which means that they can return different responses when asked the same question. This might be due to additional learning and adaption over time, language variation, changes in context, such as your chat history, and more. ## See also From 86b09733ff295a3ad157daa2d189780ffb99361a Mon Sep 17 00:00:00 2001 From: Megha Anand <88059806+anandmeg@users.noreply.github.com> Date: Sun, 15 Sep 2024 17:19:34 -0700 Subject: [PATCH 5/8] Add copilot-example.cs file --- .../how-to-6-0/csharp/copilot-example.cs | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 docs/standard/serialization/system-text-json/snippets/how-to-6-0/csharp/copilot-example.cs diff --git a/docs/standard/serialization/system-text-json/snippets/how-to-6-0/csharp/copilot-example.cs b/docs/standard/serialization/system-text-json/snippets/how-to-6-0/csharp/copilot-example.cs new file mode 100644 index 0000000000000..c7c38ae9e76f4 --- /dev/null +++ b/docs/standard/serialization/system-text-json/snippets/how-to-6-0/csharp/copilot-example.cs @@ -0,0 +1,26 @@ +using System.Text.Json; + +public class Person +{ + public string? FirstName { get; set; } + public string? LastName { get; set; } + public int Age { get; set; } + public string? Country { get; set; } +} + +public class Program +{ + public static void Main() + { + var person = new Person + { + FirstName = "John", + LastName = "Doe", + Age = 30, + Country = "USA" + }; + + string jsonString = JsonSerializer.Serialize(person); + Console.WriteLine(jsonString); + } +} From 9501ebce20140a70571e04ccf386c03d2505efa3 Mon Sep 17 00:00:00 2001 From: Megha Anand <88059806+anandmeg@users.noreply.github.com> Date: Sun, 15 Sep 2024 17:22:02 -0700 Subject: [PATCH 6/8] Add code snipped file --- .../system-text-json/customize-properties.md | 186 ++++++++---------- 1 file changed, 78 insertions(+), 108 deletions(-) diff --git a/docs/standard/serialization/system-text-json/customize-properties.md b/docs/standard/serialization/system-text-json/customize-properties.md index 0afc0ba68058d..24263840897bf 100644 --- a/docs/standard/serialization/system-text-json/customize-properties.md +++ b/docs/standard/serialization/system-text-json/customize-properties.md @@ -247,121 +247,91 @@ The following example shows you how to use Copilot to modify exisitng code to cu 1. Add the following C# example code to a code file `Example.cs` in your editor. In Visual Studio, you can use a C# console application project to try this example. - ```csharp - using System.Text.Json; - - //Create an instance of the `Person` class and initialize its properties with values. - public class Person - { - public string? FirstName { get; set; } - public string? LastName { get; set; } - public int Age { get; set; } - public string? Country { get; set; } - } - - public class Program - { - public static void Main() - { - var person = new Person - { - FirstName = "John", - LastName = "Doe", - Age = 30, - Country = "USA" - }; - - //Serialize the `person` object to a JSON string using `System.Text.Json` - string jsonString = JsonSerializer.Serialize(person); - - //Print the JSON string to the console - Console.WriteLine(jsonString); - } - } + :::code language="csharp" source="snippets/how-to-6-0/csharp/copilot-example.cs"::: + + `Example.cs` code does the following: + - Creates an instance of the `Person` class and initializes its properties with values. + - Serializes the `person` object to a JSON string using `JsonSerializer.Serialize`. + - Prints the following JSON string to the console: + ```json + {"FirstName":"John","LastName":"Doe","Age":30,"Country":"USA"} ``` - `Example.cs` code does the following: - - Creates an instance of the `Person` class and initializes its properties with values. - - Serializes the `person` object to a JSON string using `JsonSerializer.Serialize`. - - Prints the following JSON string to the console: - ```json - {"FirstName":"John","LastName":"Doe","Age":30,"Country":"USA"} - ``` 1. In Copilot Chat, enter the following prompt to modify the code to customize names and order of the JSON serialization output. - > `#Example.cs` modify code to use `System.Text.Json` to customize property names and order of JSON output from serializtion. Set property names FirstName to first_name, LastName to last_name. Set order to: Country, FirstName, LastName, Age. Provide customized serialization output. - - You can customize the prompt to output a JSON string with property names and values that suit your requirements. - - You can use chat features, such as [slash commands, references to files, methods, or classes, and threads](/visualstudio/ide/copilot-chat-context), to set intent and get better answers with scoped context. - - The following output shows an example Copilot Chat response: - - ```output - - To customize the property names and order of the JSON output using System.Text.Json, you can use the JsonPropertyName attribute to rename properties and the JsonPropertyOrder attribute to set the order. Here's how you can modify your code: - - using System.Text.Json; - using System.Text.Json.Serialization; - - public class Person - { - [JsonPropertyName("first_name")] - [JsonPropertyOrder(2)] - public string? FirstName { get; set; } - - [JsonPropertyName("last_name")] - [JsonPropertyOrder(3)] - public string? LastName { get; set; } - - [JsonPropertyOrder(4)] - public int Age { get; set; } - - [JsonPropertyOrder(1)] - public string? Country { get; set; } - } - - public class Program - { - public static void Main() - { - var person = new Person - { - FirstName = "John", - LastName = "Doe", - Age = 30, - Country = "USA" - }; - - string jsonString = JsonSerializer.Serialize(person, new JsonSerializerOptions { WriteIndented = true }); - Console.WriteLine(jsonString); - } - } - - **Explanation:** - 1. Renaming Properties: The JsonPropertyName attribute is used to rename FirstName to first_name and LastName to last_name. - 2. Ordering Properties: The JsonPropertyOrder attribute is used to set the order of the properties in the JSON output. The order is set as: - • Country (Order 1) - • FirstName (Order 2) - • LastName (Order 3) - • Age (Order 4) - 3. Indented JSON: The JsonSerializerOptions with WriteIndented = true is used to make the JSON output more readable. - - **Customized Serialization Output:** - { - "Country": "USA", - "first_name": "John", - "last_name": "Doe", - "Age": 30 - } - - This ensures that the JSON output has the customized property names and the specified order. - ``` + > `#Example.cs` modify code to use `System.Text.Json` to customize property names and order of JSON output from serializtion. Set property names FirstName to first_name, LastName to last_name. Set order to: Country, FirstName, LastName, Age. Provide customized serialization output. + + You can customize the prompt to output a JSON string with property names and values that suit your requirements. + + You can use chat features, such as [slash commands, references to files, methods, or classes, and threads](/visualstudio/ide/copilot-chat-context), to set intent and get better answers with scoped context. + + The following output shows an example Copilot Chat response: + + ```output + + To customize the property names and order of the JSON output using System.Text.Json, you can use the JsonPropertyName attribute to rename properties and the JsonPropertyOrder attribute to set the order. Here's how you can modify your code: + + using System.Text.Json; + using System.Text.Json.Serialization; + + public class Person + { + [JsonPropertyName("first_name")] + [JsonPropertyOrder(2)] + public string? FirstName { get; set; } + + [JsonPropertyName("last_name")] + [JsonPropertyOrder(3)] + public string? LastName { get; set; } + + [JsonPropertyOrder(4)] + public int Age { get; set; } + + [JsonPropertyOrder(1)] + public string? Country { get; set; } + } + + public class Program + { + public static void Main() + { + var person = new Person + { + FirstName = "John", + LastName = "Doe", + Age = 30, + Country = "USA" + }; + + string jsonString = JsonSerializer.Serialize(person, new JsonSerializerOptions { WriteIndented = true }); + Console.WriteLine(jsonString); + } + } + + **Explanation:** + 1. Renaming Properties: The JsonPropertyName attribute is used to rename FirstName to first_name and LastName to last_name. + 2. Ordering Properties: The JsonPropertyOrder attribute is used to set the order of the properties in the JSON output. The order is set as: + • Country (Order 1) + • FirstName (Order 2) + • LastName (Order 3) + • Age (Order 4) + 3. Indented JSON: The JsonSerializerOptions with WriteIndented = true is used to make the JSON output more readable. + + **Customized Serialization Output:** + { + "Country": "USA", + "first_name": "John", + "last_name": "Doe", + "Age": 30 + } + + This ensures that the JSON output has the customized property names and the specified order. + ``` When Copilot returns a code block, the response includes options to copy the code, insert the code into a new file, or preview the code output. - > [!NOTE] - > Your results might be different from what's shown in the example responses. AI models are non-deterministic, which means that they can return different responses when asked the same question. This might be due to additional learning and adaption over time, language variation, changes in context, such as your chat history, and more. +> [!NOTE] +> Your results might be different from what's shown in the example responses. AI models are non-deterministic, which means that they can return different responses when asked the same question. This might be due to additional learning and adaption over time, language variation, changes in context, such as your chat history, and more. ## See also From 0c3879c16973f25d7209783944b4e3db02ce3be6 Mon Sep 17 00:00:00 2001 From: Megha Anand <88059806+anandmeg@users.noreply.github.com> Date: Mon, 16 Sep 2024 11:39:55 -0700 Subject: [PATCH 7/8] Fix typo --- .../serialization/system-text-json/customize-properties.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/docs/standard/serialization/system-text-json/customize-properties.md b/docs/standard/serialization/system-text-json/customize-properties.md index 24263840897bf..27bd18ecde8d2 100644 --- a/docs/standard/serialization/system-text-json/customize-properties.md +++ b/docs/standard/serialization/system-text-json/customize-properties.md @@ -242,7 +242,7 @@ If you're using [Visual Studio 2022 version 17.8 or later](/visualstudio/release > [!NOTE] > GitHub Copilot is powered by AI, so surprises and mistakes are possible. Make sure to verify any generated code or suggestions. For more information about the general use of GitHub Copilot, product impact, human oversight, and privacy, see [GitHub Copilot FAQs](https://github.com/features/copilot#faq). -The following example shows you how to use Copilot to modify exisitng code to customize property names and order when serializing to JSON. +The following example shows you how to use Copilot to modify existing code to customize property names and order when serializing to JSON. 1. Add the following C# example code to a code file `Example.cs` in your editor. In Visual Studio, you can use a C# console application project to try this example. @@ -261,8 +261,7 @@ The following example shows you how to use Copilot to modify exisitng code to cu > `#Example.cs` modify code to use `System.Text.Json` to customize property names and order of JSON output from serializtion. Set property names FirstName to first_name, LastName to last_name. Set order to: Country, FirstName, LastName, Age. Provide customized serialization output. - You can customize the prompt to output a JSON string with property names and values that suit your requirements. - + `#Example.cs` in the prompt provides a [file reference as context](/visualstudio/ide/copilot-chat-context.md#reference-a-file) to Copilot. You can customize the prompt to output a JSON string with property names and values that suit your requirements. You can use chat features, such as [slash commands, references to files, methods, or classes, and threads](/visualstudio/ide/copilot-chat-context), to set intent and get better answers with scoped context. The following output shows an example Copilot Chat response: @@ -327,7 +326,6 @@ The following example shows you how to use Copilot to modify exisitng code to cu This ensures that the JSON output has the customized property names and the specified order. ``` - When Copilot returns a code block, the response includes options to copy the code, insert the code into a new file, or preview the code output. > [!NOTE] From 78590e0184f7fdac484fbbe79967464e7f49436e Mon Sep 17 00:00:00 2001 From: Megha Anand <88059806+anandmeg@users.noreply.github.com> Date: Mon, 16 Sep 2024 12:35:43 -0700 Subject: [PATCH 8/8] Fix link --- .../serialization/system-text-json/customize-properties.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/standard/serialization/system-text-json/customize-properties.md b/docs/standard/serialization/system-text-json/customize-properties.md index 27bd18ecde8d2..500cab11ea2cb 100644 --- a/docs/standard/serialization/system-text-json/customize-properties.md +++ b/docs/standard/serialization/system-text-json/customize-properties.md @@ -261,7 +261,7 @@ The following example shows you how to use Copilot to modify existing code to cu > `#Example.cs` modify code to use `System.Text.Json` to customize property names and order of JSON output from serializtion. Set property names FirstName to first_name, LastName to last_name. Set order to: Country, FirstName, LastName, Age. Provide customized serialization output. - `#Example.cs` in the prompt provides a [file reference as context](/visualstudio/ide/copilot-chat-context.md#reference-a-file) to Copilot. You can customize the prompt to output a JSON string with property names and values that suit your requirements. + `#Example.cs` in the prompt provides a [file reference as context](/visualstudio/ide/copilot-chat-context#reference-a-file) to Copilot. You can customize the prompt to output a JSON string with property names and values that suit your requirements. You can use chat features, such as [slash commands, references to files, methods, or classes, and threads](/visualstudio/ide/copilot-chat-context), to set intent and get better answers with scoped context. The following output shows an example Copilot Chat response: