I Want code for how to figure captured json format
Loading
I Want code for how to figure captured json format
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Rajkiran SwainRank #165 · 14.4K reputationPosted May 29, 2023, 6:12 AM EDT
// Sample captured JSON string const capturedJson = '{"name": "John", "age": 30, "city": "New York"}'; // Parse the JSON string into an object const parsedObject = JSON.parse(capturedJson); // Format the object to a pretty JSON string with indentation const formattedJson = JSON.stringify(parsedObject, null, 2); // Print the formatted JSON string console.log(formattedJson);Amit MohantyRank #112 · 20K reputationPosted May 29, 2023, 6:15 AM EDT
Check this:
using System; using System.Web.Script.Serialization; namespace JSONParser { class Program { static void Main(string[] args) { // Example captured JSON string string capturedJson = @" { ""name"": ""Amit Mohanty"", ""age"": 34, ""address"": { ""street"": ""123 Main St"", ""city"": ""Hyderabad"" }, ""hobbies"": [""reading"", ""running"", ""painting""] }"; // Deserialize the captured JSON string var serializer = new JavaScriptSerializer(); var parsedJson = serializer.Deserialize(capturedJson); // Print the structure of the captured JSON PrintJsonStructure(parsedJson); Console.ReadLine(); } static void PrintJsonStructure(dynamic data, int indent = 0) { foreach (var property in data) { Console.WriteLine($"{new string(' ', indent)}{property.Key}:"); if (property.Value is Dictionary) { PrintJsonStructure((Dictionary)property.Value, indent + 2); } else if (property.Value is object[]) { PrintJsonStructure((object[])property.Value, indent + 2); } else { Console.WriteLine($"{new string(' ', indent + 2)}{property.Value}"); } } } static void PrintJsonStructure(object[] array, int indent) { foreach (var item in array) { if (item is Dictionary) { PrintJsonStructure((Dictionary)item, indent + 2); } else if (item is object[]) { PrintJsonStructure((object[])item, indent + 2); } else { Console.WriteLine($"{new string(' ', indent + 2)}{item}"); } } } } }