Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Table of Contents

...

This is a bit confusing, so see Architecture>Interior Architecture for a good example of how it is used. (Asset id 309042)

The content element is used to provide extra information about the related degree where necessary. This is just a plain text field. See Economics and Finance>Actuarial Science for a good example of this (asset number 309568).

...

For example <a href='%globals_asset_url:54655^json_encode%#advisers'>link text</a> will link to http://www.victoria.ac.nz/vbs/about/staff#advisers.

 

New lines in text

If you are getting corrupt json values, there is a good chance it is because there is a newline in it somewhere. These are not allowed as they break json objects. When importing content, make sure that all newlines are replaced with:

...

This is then turned into <p> tags via the angular app where necessary, but this should not cause an issue.

 

JSON specifics in formatting and common pitfalls

Firstly, make sure you have read the above content about New Lines in Text, this has been the number one cause for issues so far.

Online json validator

If you have recently made a change to a block and the page is no longer rendering, copy and paste that block into the online json checker here and see if it can detect the issue for you.

Most common issues

The " character must be escaped, like so \". The " character is what json uses to know where contents start and end, so if it appears within a piece of content somewhere, it will think that it has ended early and will break itself.

This is particularly prevalent with quotes, as they often start/end with " characters. HOWEVER, there is another character we use for quotes, which is the “ and ” character - which 'don't' need escaping. So, if you have “ in your text and it is still working, that is why.

One other caveat with this, often where html text appears within content it will be used like so:

Code Block
<a href="http://www.victoria.ac.nz">link</a>

The " in that will break json. You can either escape them, or replace them with the ' character like so:

Code Block
<a href='http://www.victoria.ac.nz'>link</a>

And it will work fine.

Arrays

The way json normally works, is that each value will have a name, a colon, and then a value associated with it, followed by a comma.

For example:

Code Block
{
	"contentType"  : "content-plain",
	"heading"      : "Learn from the best",
	"content"      : "Learn from internationally acclaimed researchers and thinkers.\nTheir experience and collaboration with industry professionals mean you'll get best learning opportunities."
}

important Notice a comma after every value except the last one. The comma basically says 'there is another value after this one'. Some validators will allow a comma after the last value, but there are some places inside squiz where it will make the json object not valid and break things)

Arrays work similarly, however they have no name associated with them. So, in the above case, if the content were an array instead of a value, it would look like this:

Code Block
{
	"contentType"  : "content-plain",
	"heading"      : "Learn from the best",
	"content"      : [
         "Learn from internationally acclaimed researchers and thinkers.\nTheir experience and collaboration with industry professionals mean you'll get best learning opportunities."
    ]
}

This allows us to have multiple values all referenced by the same name. Which looks like this:

Code Block
{
	"contentType"  : "content-plain",
	"heading"      : "Learn from the best",
	"content"      : [
         "Learn from internationally acclaimed researchers and thinkers.\nTheir experience and collaboration with industry professionals mean you'll get best learning opportunities.",
         "Learn from internationally acclaimed researchers and thinkers.\nTheir experience and collaboration with industry professionals mean you'll get best learning opportunities.",
         "Learn from internationally acclaimed researchers and thinkers.\nTheir experience and collaboration with industry professionals mean you'll get best learning opportunities.",
         "Learn from internationally acclaimed researchers and thinkers.\nTheir experience and collaboration with industry professionals mean you'll get best learning opportunities."
    ]
}

Notice how inside the array, there is no comma after the last element in the list. As mentioned before, this lets the json object know that this is the last object in that array, and not to expect anything else.

The commas are a particularly nasty issue, because nearly every json parser will allow there to be a comma after the last element without issue. The json interpreter within squiz though does not, and so some values that the angular app needs might be missing - such as the contentType and the region. Use the online validator here if you are unsure whether your commas are correct or not.