2022.1

Table Of Contents
The next script loads a remote snippet (see "Remote snippets" on page282), looks for an H1
heading and uses that text.
var post = loadhtml('snippets/post.rhtml');
var h1 = query('h1', post).text();
results.text(h1);
Another example is given in the following how-to: Using a selector to load part of a snippet.
loadjson()
Creates a JSON object based on the text retrieved fromthe suppliedlocation. The function lets
you retrieve content from a JSON enabled server using a standard HTTP request. Popular
content management systems like WordPress (requires JSON API plugin) and Drupalprovide
a JSON service/API to retrieve content.
Note
l The specified JSON file is expected to be UTF-8, UTF-16 or UTF-32 encoded. A
byte order mark specified as the first character will be stripped. Saving any changes
will change the encoding to UTF-8.
l Loadjson() is cached per batch run (based on the URL) in print/email.
l This online JSON viewer is handy to debug JSON data: http://jsonviewer.stack.hu
Tip
External content is not loaded while editing a script. To test a script that loads external
content, you can do a preflight; see "Doing a Preflight" on page401.
loadjson(location)
Loads json data from the specified location.
location
String; the supplied location should be either a URL or a relative filepath. The file protocol
is supported as well as the http/https protocols. The complete syntax of a fully qualified
Page 814