In your page-fragment's pre-page script, you can create an EWD Session ResultSet, eg:

 d deleteFromSession^%zewdAPI("searchResults",sessid)
 s propsArray("name")="Rob"
 s propsArray("town")="London"
 s propsArray("country")="UK"
 d mergeRecordArrayToResultSet^%zewdAPI("searchResults",.propsArray,sessid)
 s propsArray("name")="Chris"
 s propsArray("town")="Banstead"
 s propsArray("country")="UK"
 d mergeRecordArrayToResultSet^%zewdAPI("searchResults",.propsArray,sessid)
 s propsArray("name")="John"
 s propsArray("town")="Portland"
 s propsArray("country")="USA"
 d mergeRecordArrayToResultSet^%zewdAPI("searchResults",.propsArray,sessid)

Now convert this Session ResultSet to a JSON string and save it as a session variable:

  d setJSONValue^%zewdAPI("jsonrs","searchResults",sessid)

In this example we now have a session variable named jsonrs that contains the JSON string defining the searchResults resultSet.

Note: calling the setJSONValue() method automatically sets read access for the Session ResultSet (searchResults in this example) so that it can be fetched into the browser using JSON.

You can now load this JSON string into your page fragment by adding the ewd.getJSON() pseudo-function into a Javascript tag:

  <script language="javascript">
    ewd.getJSON(#jsonrs) ;
  </script>

This is simply a shortcut that is synonymous with:

  <script language="javascript">
    eval('<?= #jsonrs ?>') ;
  </script>

You can use either syntax depending on your preference.

When the fragment loads, the searchResults object will be instantiated in Javascript and will be available from that point forwards. Each resultSet record/property is accessible in Javascript using the syntax:

  resultSetName[recordNo].propertyName

For example:

  alert('John lives in " + searchResults[3].town) ;

Note: you can view a Javascript Object as a JSON String using the toJsonString() method:

  alert(toJsonString(searchResults)) ;