1

I have the following code which prints out json to my page

http://screencast.com/t/ASe6sUW64R1

the code is as follows

public async Task<ActionResult> TestRestCall()
        {
            Uri serviceRoot = new Uri(azureAdGraphApiEndPoint);
            var token = await GetAppTokenAsync();
            string requestUrl = "https://graph.windows.net/mysaasapp.onmicrosoft.com/users?api-version=2013-04-05";

            HttpClient hc = new HttpClient();
            hc.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue(
                "Bearer", token);

            HttpResponseMessage hrm = await hc.GetAsync(new Uri(requestUrl));

            if (hrm.IsSuccessStatusCode)
            {
                ViewBag.Message = JObject.Parse(await hrm.Content.ReadAsStringAsync()).ToString(Formatting.Indented) ;
                return View();
            }
            else
            {
                return View();
            }

        }

However for debugging purposes, I would like to show the JSON nicely to read it better, but code is not working as I found in another SO answer

Luis Valencia
  • 32,619
  • 93
  • 286
  • 506
  • Are you using SyntaxHighliter script? http://stackoverflow.com/questions/4810841/how-can-i-pretty-print-json-using-javascript – Aram May 22 '15 at 23:51

2 Answers2

2

You can use https://github.com/umbrae/jsonlintdotcom/blob/master/c/js/jsl.format.js to render json nicely. As it says:

jsl.format - Provide json reformatting in a character-by-character approach, so that even invalid JSON may be reformatted (to the best of its ability).

Or https://stackoverflow.com/a/8007860/250849

Community
  • 1
  • 1
vmg
  • 9,920
  • 13
  • 61
  • 90
1

Possible, Postman is what you need. It will render your json in readable format.Also it's a nice debugging tool.

Anton Putau
  • 632
  • 1
  • 7
  • 31