<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Style JSON Data &#8211; Sibeesh Passion</title>
	<atom:link href="https://mail.sibeeshpassion.com/tag/style-json-data/feed/" rel="self" type="application/rss+xml" />
	<link>https://mail.sibeeshpassion.com</link>
	<description>My passion towards life</description>
	<lastBuildDate>Tue, 10 Jul 2018 07:54:26 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>/wp-content/uploads/2017/04/Sibeesh_Passion_Logo_Small.png</url>
	<title>Style JSON Data &#8211; Sibeesh Passion</title>
	<link>https://mail.sibeeshpassion.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Style Or Format JSON Data In JQuery</title>
		<link>https://mail.sibeeshpassion.com/style-or-format-json-data-in-jquery/</link>
					<comments>https://mail.sibeeshpassion.com/style-or-format-json-data-in-jquery/#disqus_thread</comments>
		
		<dc:creator><![CDATA[SibeeshVenu]]></dc:creator>
		<pubDate>Tue, 31 May 2016 00:00:34 +0000</pubDate>
				<category><![CDATA[How to]]></category>
		<category><![CDATA[JQuery]]></category>
		<category><![CDATA[Format JSON]]></category>
		<category><![CDATA[How To]]></category>
		<category><![CDATA[Json]]></category>
		<category><![CDATA[JSON in Pre Tag]]></category>
		<category><![CDATA[Style JSON Data]]></category>
		<guid isPermaLink="false">http://sibeecst_passion.com/?p=11648</guid>

					<description><![CDATA[In this post we will discuss how we can format or style the JSON you get from the server. Sometimes you may need to show the exact JSON you get from your API or from server in your web page. Normally if you just bind this JSON to any pre tag, it will look like just a straight line. Isn&#8217;t it? To overcome this we have an option in jQuery . I hope you will like this. Background For the past few months I am working with some Web API projects. As you all know the preferred output of an [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>In this post we will discuss how we can format or style the <a href="http://sibeeshpassion.com/tag/json/" target="_blank">JSON </a>you get from the server. Sometimes you may need to show the exact JSON you get from your API or from server in your web page. Normally if you just bind this JSON to any pre tag, it will look like just a straight line. Isn&#8217;t it? To overcome this we have an option in <a href="http://sibeeshpassion.com/category/jQuery/" target="_blank">jQuery </a>. I hope you will like this.</p>
<p><strong>Background</strong></p>
<p>For the past few months I am working with some <a href="http://sibeeshpassion.com/category/web-api/" target="_blank">Web API</a> projects. As you all know the preferred output of an API is JSON, I am returning JSON from my API. I wanted to show this JSON in a Pre tag as a result, but in a formatted way or stylish way. Here I am going to explain how we can do this. </p>
<p><strong>Using the code</strong></p>
<p>Before getting started, please make sure that you have added the jQuery reference to your page.</p>
<p>[html]<br />
 &lt;script src=&quot;scripts/jquery-2.2.3.js&quot;&gt;&lt;/script&gt;<br />
[/html]</p>
<p>Now let us say we are getting a JSON as follows from our API.</p>
<p>[js]<br />
[{&quot;AreaCode&quot;:&quot;B697-31&quot;,&quot;Revenue&quot;:12747128.190000001},{&quot;AreaCode&quot;:&quot;B697-92&quot;,&quot;Revenue&quot;:7922559.1600000048},{&quot;AreaCode&quot;:&quot;B697-76&quot;,&quot;Revenue&quot;:7541039.540000001},{&quot;AreaCode&quot;:&quot;B697-46&quot;,&quot;Revenue&quot;:7076495.5800000066},{&quot;AreaCode&quot;:&quot;B553-131&quot;,&quot;Revenue&quot;:5738816.5099999979},{&quot;AreaCode&quot;:&quot;B553-193&quot;,&quot;Revenue&quot;:4608556.52},{&quot;AreaCode&quot;:&quot;B697-74&quot;,&quot;Revenue&quot;:3895194.1099999994},{&quot;AreaCode&quot;:&quot;D158-233&quot;,&quot;Revenue&quot;:3572808.989999996},{&quot;AreaCode&quot;:&quot;B697-78&quot;,&quot;Revenue&quot;:3512657.6999999937},{&quot;AreaCode&quot;:&quot;B672-31&quot;,&quot;Revenue&quot;:2955916.9800000032},{&quot;AreaCode&quot;:&quot;B553-46&quot;,&quot;Revenue&quot;:2806813.7100000042}]<br />
[/js]</p>
<p>It will obviously looks like preceding when you just append it to a pre tag.</p>
<div id="attachment_11650" style="width: 526px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/05/JSON-in-Pre-Tag.png"><img fetchpriority="high" decoding="async" aria-describedby="caption-attachment-11650" src="http://sibeeshpassion.com/wp-content/uploads/2016/05/JSON-in-Pre-Tag.png" alt="JSON in Pre Tag" width="516" height="115" class="size-full wp-image-11650" srcset="/wp-content/uploads/2016/05/JSON-in-Pre-Tag.png 516w, /wp-content/uploads/2016/05/JSON-in-Pre-Tag-300x67.png 300w, /wp-content/uploads/2016/05/JSON-in-Pre-Tag-400x89.png 400w" sizes="(max-width: 516px) 100vw, 516px" /></a><p id="caption-attachment-11650" class="wp-caption-text">JSON in Pre Tag</p></div>
<p>Now we will format this JSON string with JQuery Parse and JQuery stringify method as follows. </p>
<p>[js]<br />
  var tmpData = JSON.parse(data);<br />
                    var formattedData = JSON.stringify(tmpData, null, &#8216;\t&#8217;);<br />
                    $(&#8216;#output&#8217;).text(formattedData);<br />
[/js]</p>
<p>Here output is the id of our pre tag which we defined as follows.</p>
<p>[html]<br />
&lt;pre id=&quot;output&quot;&gt;&lt;/pre&gt;<br />
[/html]</p>
<p>Now if you bind the data after the formatting to pre tag, you will get an out put as follows. </p>
<div id="attachment_11651" style="width: 526px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/05/JSON-in-Pre-Tag-Output.png"><img decoding="async" aria-describedby="caption-attachment-11651" src="http://sibeeshpassion.com/wp-content/uploads/2016/05/JSON-in-Pre-Tag-Output.png" alt="JSON in Pre Tag Output" width="516" height="861" class="size-full wp-image-11651" srcset="/wp-content/uploads/2016/05/JSON-in-Pre-Tag-Output.png 516w, /wp-content/uploads/2016/05/JSON-in-Pre-Tag-Output-180x300.png 180w, /wp-content/uploads/2016/05/JSON-in-Pre-Tag-Output-400x667.png 400w, /wp-content/uploads/2016/05/JSON-in-Pre-Tag-Output-360x600.png 360w" sizes="(max-width: 516px) 100vw, 516px" /></a><p id="caption-attachment-11651" class="wp-caption-text">JSON in Pre Tag Output</p></div>
<p><strong>Conclusion</strong></p>
<p>Did I miss anything that you may think which is needed? Could you find this post as useful? I hope you liked this article. Please share me your valuable suggestions and feedback.</p>
<p><strong>Your turn. What do you think?</strong></p>
<p>A blog isn&#8217;t a blog without comments, but do try to stay on topic. If you have a question unrelated to this post, you’re better off posting it on C# Corner, Code Project, Stack Overflow, Asp.Net Forum instead of commenting here. Tweet or email me a link to your question there and I’ll definitely try to help if I can.</p>
<p>Kindest Regards<br />
Sibeesh Venu</p>
]]></content:encoded>
					
					<wfw:commentRss>https://mail.sibeeshpassion.com/style-or-format-json-data-in-jquery/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
