• Anonymous
  • Login
  • Register
JSON LotusScript Classes

Owners Troy Reimer Category
Data Integration
Software Development Tools
Web Development Tools
Contributors - Platform
R 8.5.2
Downloads 1269 Last Release Aug 10, 2010
Rating
(2 ratings)
Project Creation Jan 28, 2008
Status Not active Short URL Not defined
Description LotusScript implementation of a reader and writer for JSON In Catalog
No


Note: Changed the license to the Apache License.

Introduction
The attached database (json.nsf) contains LotusScript classes for parsing and creating JSON text. These classes are contained in five script libraries: ls.snapps.JSONArray, ls.snapps.JSONObject, ls.snapps.JSONReader, ls.snapps.JSONWriter, and ls.snapps.JSONWrapperConverters. The JSONArray and JSONObject classes are wrapper classes that are used by the JSONReader class. There are two versions of the wrapper classes as detailed below. Additional information can be found in the "Help - About This Database" document.

These classes are based on the specification detailed at http://www.json.org. This includes handling escaped characters and numbers as specified. It is noted below, but the JSONWriter class outputs dates in the following format: yyyy/mm/dd hh:mm:ss UTC+|-hh:mm. This is so that JavaScript can easily convert the text into a Date object.


JSONReader
This class provides a way to parse JSON text into either a JSONObject or JSONArray object or some combination. However, it will always return some type of custom object (if the JSON is valid). Both the JSONObject and JSONArray classes have an Items property. You can put the value of the returned object Items property into a variant and then step through the results. See the ls.snapps.JSONReader library for additional documentation.

Public Method :
-Parse (JSON string)
This method returns either a JSONArray or a JSONObject or some combination.


JSONWriter
This class provides two ways of outputing JSON text. The first is to pass an array, list, NotesDocument, NotesDocumentCollection, NotesView, NotesViewEntryCollection, or NotesViewEntry to the ToJSON method. This will render the object as JSON. If the object is a type of view object, the output will be taken from the column values. The output data is basically the same as the properties/values of NotesViewEntry. If the object is a document, its output follows the NotesDocument properties/values. However, there are several properties to change how data should be output (see below).
See the ls.snapps.JSONWriter library for additional documentation.

NOTE: For NotesDocuments, all field data is placed into the "Items" object. Field names are set to lowercase. The value of the field is in an array called "Values". The datatype is put in "Type".
"Items":{"field1":{"Values":["my value"],"Type":"TEXT"}}

NOTE: Date output format: yyyy/mm/dd hh:mm:ss UTC+|-hh:mm

Output examples:
Single document (default):
{"UNID":
{"Authors":["CN=Troy Reimer\/O=SNA"],...,"Items":{"field1": ...}}
}

Single document (OutputAsArray = true):
[
{"Authors":["CN=Troy Reimer\/O=SNA"],...,"Items":{"field1": ...}}
]

Multiple documents (default):
{
"unid1":{"Authors":["CN=Troy Reimer\/O=SNA"],...,"Items":{"field1":...}},
"unid2":{"Authors":["CN=Troy Reimer\/O=SNA"],...,"Items":{"field1":...}}
}


Multiple documents (OutputAsArray = true):
[
{"Authors":["CN=Troy Reimer\/O=SNA"],...,"Items":{"field1": ...}},
{"Authors":["CN=Troy Reimer\/O=SNA"],...,"Items":{"field1": ...}}
]

This class also provides an pseudo-object oriented way of creating JSON text. Each public method returns a string with the JSON text requested. It generates an error if arrays and objects are not begun and ended in the correct order. The first method called must be either BeginArray or BeginObject. The AppendValue method accepts only scalar values.


Public Properties :
-IncludeRichTextItems (boolean, default is True)
Excludes RichTextItem values if set to false.
-OuputAsArray (boolean, default is False)
Outputs the JSON as an array instead of as an associative array (see above)
-OutputViewAsDocuments(boolean, default is False)
Outputs documents found in the view as NotesDocuments instead of as NotesViewEntries
-TruncateRichText (long)
Sets the number of characters to output from RichTextItems.

Public Methods :
-AppendJSON(JSON string)
Assumes the input text is valid JSON and appends it to the end of the JSON string being built
-AppendValue(Value(s))
Appends the input value to the JSON string
-BeginArray
Begins an array (i.e. "[")
-BeginCallbackFunction(Function name)
Begins the JavaScript callback function input
-BeginObject
Begins an object (i.e. "{")
-EndArray
Ends an array (i.e. "]")
-EndCallbackFunction
Ends the callback function
-EndObject
Ends an object (i.e. "}")
-Key(Name)
Appends the name of a key to the JSON string
-SetFieldsToOutput(array)
Sets the fields to output from a NotesDocument object
-ToJSON(Array | List | NotesDocument | NotesDocumentCollection | View | NotesViewEntryCollection | NotesViewEntry)
Converts the input into a JSON string


Wrapper classes
The following wrapper classes are used by the JSONReader class to parse the JSON string into Lotuscript objects. The classes below are defined in the ls.snapps.JSONArray, ls.snapps.JSONObject libraries. The ls.snapps.JSONWrapperConverters library defines both classes and allows you to convert the object back to a JSON string. This is accomplished internally by including the ls.snapps.JSONWriter in the converters library. If you need lighter weight versions of the classes, you can use the ones in the ls.snapps.JSONObject and ls.snapps.JSONArray libraries.


JSONArray
This is a wrapper class used by the JSONReader to represent an array. If you use the JSONArray class defined in the ls.snapps.JSONWrapperConverters library, you can convert the JSONArray back to a JSON string using the ToJSON method.

Public Properties :
-Count
Returns a count of the number of items in the array
-Items
Returns the items in the array as a Variant

Public Methods :
-AddItem(Value)
Adds the input value to the JSONArray
-RemoveItem(Index)
Remove the item of the input index from the JSONArray
-ReplaceItemValue(Index, Value)
Replaces the item in the JSONArray at the input Index with the input Value
-ToJSON only available in the ls.class.JSONWrapperConverters library
Returns the JSONArray as a JSON string


JSONObject
This is a wrapper class used by the JSONReader to represent an object. The name/value pairs are stored internally in a List variable. If you use the JSONObject class defined in the ls.snapps.JSONWrapperConverters library, you can convert the JSONObject back to a JSON string using the ToJSON method.

Public Properties:
-Count
Number of items in the list
-Items
Returns the items as a List

Public Methods:
-AddItem(Name, Value)
Adds the input value to the JSONObject
-GetItemValue(Name)
Returns the value of the specified item
-RemoveItem(Name)
Removes the named item from the JSONObject
-ReplaceItemValue(Name, Value)
Replaces the named item in the JSONObject List with the input value
-ToJSON only available in the ls.class.JSONWrapperConverters library
Returns the JSONObject as a JSON string


Projects can have short and readable URLs, e.g. http://mobilecontrols.openntf.org.

You can request a short URL to your project by sending a mail to support at openntf dot org. Put the word 'OpenNTF' somewhere in the subject.
Owners are the people with maximal rights. For example they can create releases and add more contributors.

In order to define multiple owners use "," (comma) as separator.

Because of data privacy you cannot lookup other people's names but you have to type them in.
Enter the contributors or owners here who you want to receive notifications and questions by email.

In order to define multiple owners use "," (comma) as separator.

Because of data privacy you cannot lookup other people's names but you have to type them in.
In addition to the owners additional OpenNTF contributors have to be listed here. Contributors don't have the same access rights as owners, e.g. they cannot create releases.

In order to define multiple owners use "," (comma) as separator.

Because of data privacy you cannot lookup other people's names but you have to type them in.
Enter a short description of the project here (up to 100 characters).

The short description shows up in the project UI and in some of the views.
In this field you should enter a more detailed description of your project.

You can use the rich text editor for rich text formating. You can also enter HTML to embed objects, e.g. to embed a YouTube video or a screenshot of the project. In this case use '[' and ']' to mark the passthrough HTML as such.

Please note that the first time you use the new UI your description is converted from rich text to MIME. You might want to copy and paste the raw plain text from the old UI in the new UI so that you don't loose information.
A Catalog Release is for projects that are production ready and that are end-user "install friendly".

This property describes whether any release of this project has been added to the catalog.

Learn more about the catalog.