StringValue (Json function)

From m204wiki
Jump to navigation Jump to search

Get string value of JSON object (Json class)

[Introduced in Model 204 7.6]

This function returns the number value of a Json object of the string type.

Syntax

%unicode = json:StringValue Throws InvalidJsonType

Syntax terms

%unicodeThe value of the json string data which, as the name suggests, is always unicode though if the target is EBCDIC, the unicode is converted automatically into EBCDIC.
Json Json object, which must have an underlying string type. If the Json object does not have the string type, an InvalidJsonType exception is thrown.

Usage notes

  • If the Json object has a number value, while that numebr can always be converted to a string, the String method will still throw an InvalidJsonType exception. If one wishes to extract a Json string from a number object, extract it with the NumberValue function and then assign it to a string (String, Longstring, or Unicode) variable.
  • The type of a Json object can be determined with the Type function.
  • While the result of StringValue will be automatically converted to EBCDIC as needed, if the source might contain untranslatable unicode characters, this automatic assignment could result in a request canceling error. If this is a potential issue, use unicode variables to hold all the data or apply the UnicodeToEbcdic function to the StringValue result and catch the possible CharacterTranslationException.

Examples

The following example finds the lexicographically smallest value in an array and prints it:

b %json is object json %i is float %min is string len 32 %json = array("United States", "Canada", "Mexico", "Belize", "Nicaragua") %min = %json(1):stringValue for %i from 2 to %json:count if %min gt %json(%i):stringValue then %min = %json(%i):stringValue end if end for printText {~=%min} end

This prints:

%min=Belize

See also