Note that there are some explanatory texts on larger screens.

plurals
  1. POOutput JSON with Umbraco template using Razor
    text
    copied!<p>I've encountered a situation where I need to replicate some JSON so that an area of the website can be content-managed. I have a <strong>json</strong> file I need to replicate. The taxonomy of the site is complex and unfortunately I am not in a position to change this. </p> <p>I have set up the template in Umbraco and the data that I want is displaying on a page, but I do not know how to convert this to output as JSON.</p> <p>Razor looks like this:</p> <pre><code> @{ dynamic memberships = Library.NodeById(1081); var packageGroups = memberships.Descendants("Price"); foreach(var package in packageGroups) { var top = package.AncestorOrSelf("Type"); var Description = (@top.HasValue("Blurb")) ? @top.Blurb : @top.Description; var Locations = ""; foreach(var item in package.UserLocation.ToString().Split(',')) { Locations += @Model.NodeById((@item)).Name; Locations += ","; } &lt;ul&gt; &lt;li&gt;Maintitle: @top.Parent().Title&lt;/li&gt; &lt;li&gt;Title: @top.Title&lt;/li&gt; &lt;li&gt;SubTitle: @SubTitle&lt;/li&gt; &lt;li&gt;Description: @Description&lt;/li&gt; &lt;li&gt;Link: @top.Url&lt;/li&gt; &lt;li&gt;Location: @Locations&lt;/li&gt; &lt;li&gt;Render: true&lt;/li&gt; &lt;/ul&gt; } } </code></pre> <p>I need to output this to replicate the JSON file as below:</p> <pre><code> { "items":[ { "MainTitle":"Package Top Level Title", "Title":"Package Title", "SubTitle":"Additional Details", "Description":"We wil provide you with some great products and services.", "Link":"/path/to/package/", "Location":[ "Saturn" ], "Render":true }, ] } </code></pre> <p>Pointers appreciated.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload