Groovy variables can hold any type of object, and often it is not clear whether a certain object is a json string, a json object or a map. When there is any doubt, the parser can help make sure that an object is in the expected format. If any of these methods return null, possibly the parameter cannot be converted to the desired format. In that case, call parser.lasterror to obtain the error text.

 

 

Method

Purpose

Example

asMap(object)

Convert object to map


asList(object)

Convert object to list

 

asValue(object)

Extract the “value” (String or number) from the object

 

asJson(object)

Convert object to json string

 

asPrettyJson(object)

Convert and format json string