What is the easiest way to manage JSON data in C#?

William Thompson 120 Reputation points
2024-09-09T23:38:10.44+00:00

Thank you for this very helpful forum.

I have this API request that is a GET request and it returns a massive JSON text. So, what is the easiest way to make the JSON file properly formatted and usable? This is what the code looks like, by the way, that gets the massive text return. The way it is now, when the code is run, it dumps the unformatted text to the console.

code-that-works

Please advise and, again, much thanks for this service.

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,858 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Karen Payne MVP 35,406 Reputation points
    2024-09-09T23:45:49.1966667+00:00

    Use the following.

    Console.WriteLine(JsonSerializer.Serialize(TODO, new JsonSerializerOptions { WriteIndented = true }));	
    

  2. Olaf Helper 44,311 Reputation points
    2024-09-11T15:04:08.0366667+00:00
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.