This is the main processing script that runs each time a new message
arrives. The message has already been validated against the schema, so the
script can assume that any required fields are present in the resulting
input.Json
object.
There are two broad approaches to processing a message.
Call app.ProcessJson(). This
recursively descends through the JSON object, applying callbacks at
each stage.
Manually extract information from the input.Json
object and construct app.WritePoint calls from that
information.
Before calling app.ProcessJson, you can extract
specific information from input.Json to set variables
that will be used by the processing callbacks. One common case is a message
that contains a single timestamp and multiple data values. In that case, you
could extract the timestamp and store it in a local variable, then create a
custom app.ValueProcessor that writes a data
point value using app.WritePoint with this timestamp. To
avoid creating a new data point containing this timestamp, set app.ExcludePaths to omit the JSON field
containing the timestamp.
When working with JSON tokens, all public members of
JToken, JArray,
JObject and JProperty are
supported. See the Newtonsoft.Json.Linq documentation for more information. In
addition to the built-in methods, the following methods are also
available:
JProperty.FullName(property,parentName)
Returns the concatenation of parentName +
“/” + the property name.
JObject.ObjectProperties()
Returns a
List
representing all direct child properties of the object whose
values are JPropertyJObjects.
JObject.ArrayProperties()
Returns a
List
representing all direct child properties of the object whose
values are JPropertyJArrays.
JObject.AllProperties()
Returns a
List
representing all direct child properties of the object.JProperty
JObject.ScalarNames()
Returns a
List
containing the names of all direct child properties whose values
are scalar values.string
JObject.ArrayNames()
Returns a
List
containing the names of all direct child properties whose values
are arrays.string
JObject.ObjectNames()
Returns a
List
containing the names of all direct child properties whose values
are objects.string
JToken.GetDate(propertyName)
Returns a DateTime produced by
converting the value of the child property identified by
.
The conversion from the property value to a
propertyNameDateTime follows these rules:
o If the value is a string, attempt to parse the value as an ISO-8601 timestamp.
If the value is a number:
If the value is > 10 *
Int32.MaxValue, treat the value as a
JSON timestamp (number of milliseconds since Jan. 1,
1970)
Else, if the value is >
20,000, treat the value as a UNIX
timestamp (number of seconds since Jan. 1,
1970)
Else, if the value is > 0,
treat the value as an OADate
(days since midnight, December 30, 1899)
Else, return Jan. 1, 1970.
If the value is a Date, return the
date unmodified.
The following functions are available to interpret timestamps. All UNIX
and JSON timestamps are assumed to be in UTC. All
DateTime results from timestamp conversion
functions are explicitly in UTC.
DoubleToDateTime(value)
Convert a number to a DateTime
according to the number rules in
JToken.GetDate() above.
GetDate(JValue)
Convert a JSON token to a DateTime
according to the rules in JToken.GetDate()
above.
DateFromIsoString(string)
Convert a string in ISO-8601 format to a
DateTime.
DateFromUnixTime(seconds)
Convert a UNIX timestamp (seconds since Jan. 1, 1970) to a
DateTime.
DateFromJsonTime(milliseconds)
Convert a JSON timestamp (milliseconds since Jan. 1, 1970) to
a DateTime.
DateFromOADate(days)
Convert an OADate (days since midnight,
December 30, 1899) to a DateTime.