JSONGenerator Class
Contains methods used to serialize objects into JSON content using the standard JSON encoding.
The System.JSONGenerator class is provided to enable the generation of standard JSON-encoded content and gives you more control on the structure of the JSON output.
See Also
The following are methods for JSONGenerator. All are instance methods.
-
Closes the JSON generator.
-
Returns the generated JSON content.
-
Returns
trueif the JSON generator is closed; otherwise, returnsfalse. -
Writes the specified
Blobvalue as a base64-encoded string. -
writeBlobField(fieldName, blobValue)
Writes a field name and value pair using the specified field name and BLOB value.
-
Writes the specified Boolean value.
-
writeBooleanField(fieldName, booleanValue)
Writes a field name and value pair using the specified field name and Boolean value.
-
Writes the specified date value in the ISO-8601 format.
-
writeDateField(fieldName, dateValue)
Writes a field name and value pair using the specified field name and date value. The date value is written in the ISO-8601 format.
-
Writes the specified date and time value in the ISO-8601 format.
-
writeDateTimeField(fieldName, datetimeValue)
Writes a field name and value pair using the specified field name and date and time value. The date and time value is written in the ISO-8601 format.
-
Writes the ending marker of a JSON array (’]’).
-
Writes the ending marker of a JSON object (’}’).
-
Writes a field name.
-
Writes the specified ID value.
-
writeIdField(fieldName, identifier)
Writes a field name and value pair using the specified field name and identifier value.
-
Writes the JSON null literal value.
-
Writes a field name and value pair using the specified field name and the JSON null literal value.
-
Writes the specified decimal value.
-
Writes the specified double value.
-
Writes the specified integer value.
-
Writes the specified long value.
-
writeNumberField(fieldName, number)
Writes a field name and value pair using the specified field name and decimal value.
-
writeNumberField(fieldName, number)
Writes a field name and value pair using the specified field name and double value.
-
writeNumberField(fieldName, number)
Writes a field name and value pair using the specified field name and integer value.
-
writeNumberField(fieldName, number)
Writes a field name and value pair using the specified field name and long value.
-
Writes the specified Apex object in JSON format.
-
writeObjectField(fieldName, value)
Writes a field name and value pair using the specified field name and Apex object.
-
Writes the starting marker of a JSON array (’[’).
-
Writes the starting marker of a JSON object (’{’).
-
Writes the specified string value.
-
writeStringField(fieldName, stringValue)
Writes a field name and value pair using the specified field name and string value.
-
Writes the specified time value in the ISO-8601 format.
-
writeTimeField(fieldName, timeValue)
Writes a field name and value pair using the specified field name and time value in the ISO-8601 format.
Closes the JSON generator.
public Void close()
Type: Void
No more content can be written after the JSON generator is closed.
Returns the generated JSON content.
public String getAsString()
Type: String
This method closes the JSON generator if it isn’t closed already.
Returns true if the JSON generator is closed; otherwise, returns false.
public Boolean isClosed()
Type: Boolean
Writes the specified Blob value as a base64-encoded string.
public Void writeBlob(Blob blobValue)
- blobValue: Type: Blob
Type: Void
Writes a field name and value pair using the specified field name and BLOB value.
public Void writeBlobField(String fieldName, Blob blobValue)
Type: Void
Writes the specified Boolean value.
public Void writeBoolean(Boolean blobValue)
- blobValue: Type: Boolean
Type: Void
Writes a field name and value pair using the specified field name and Boolean value.
public Void writeBooleanField(String fieldName, Boolean booleanValue)
Type: Void
Writes the specified date value in the ISO-8601 format.
public Void writeDate(Date dateValue)
- dateValue: Type: Date
Type: Void
Writes a field name and value pair using the specified field name and date value. The date value is written in the ISO-8601 format.
public Void writeDateField(String fieldName, Date dateValue)
Type: Void
Writes the specified date and time value in the ISO-8601 format.
public Void writeDateTime(Datetime datetimeValue)
- datetimeValue: Type: Datetime
Type: Void
Writes a field name and value pair using the specified field name and date and time value. The date and time value is written in the ISO-8601 format.
public Void writeDateTimeField(String fieldName, Datetime datetimeValue)
Type: Void
Writes the ending marker of a JSON array (’]’).
public Void writeEndArray()
Type: Void
Writes the ending marker of a JSON object (’}’).
public Void writeEndObject()
Type: Void
Writes a field name.
public Void writeFieldName(String fieldName)
- fieldName: Type: String
Type: Void
Writes the specified ID value.
public Void writeId(ID identifier)
- identifier: Type: ID
Type: Void
Writes a field name and value pair using the specified field name and identifier value.
public Void writeIdField(String fieldName, Id identifier)
Type: Void
Writes the JSON null literal value.
public Void writeNull()
Type: Void
Writes a field name and value pair using the specified field name and the JSON null literal value.
public Void writeNullField(String fieldName)
- fieldName: Type: String
Type: Void
Writes the specified decimal value.
public Void writeNumber(Decimal number)
- number: Type: Decimal
Type: Void
Writes the specified double value.
public Void writeNumber(Double number)
- number: Type: Double
Type: Void
Writes the specified integer value.
public Void writeNumber(Integer number)
- number: Type: Integer
Type: Void
Writes the specified long value.
public Void writeNumber(Long number)
- number: Type: Long
Type: Void
Writes a field name and value pair using the specified field name and decimal value.
public Void writeNumberField(String fieldName, Decimal number)
Type: Void
Writes a field name and value pair using the specified field name and double value.
public Void writeNumberField(String fieldName, Double number)
Type: Void
Writes a field name and value pair using the specified field name and integer value.
public Void writeNumberField(String fieldName, Integer number)
Type: Void
Writes a field name and value pair using the specified field name and long value.
public Void writeNumberField(String fieldName, Long number)
Type: Void
Writes the specified Apex object in JSON format.
public Void writeObject(Object anyObject)
- anyObject: Type: Object
Type: Void
Writes a field name and value pair using the specified field name and Apex object.
public Void writeObjectField(String fieldName, Object value)
- fieldName: Type: String
- value: Type: Object
Type: Void
Writes the starting marker of a JSON array (’[’).
public Void writeStartArray()
Type: Void
Writes the starting marker of a JSON object (’{’).
public Void writeStartObject()
Type: Void
Writes the specified string value.
public Void writeString(String stringValue)
- stringValue: Type: String
Type: Void
Writes a field name and value pair using the specified field name and string value.
public Void writeStringField(String fieldName, String stringValue)
Type: Void
Writes the specified time value in the ISO-8601 format.
public Void writeTime(Time timeValue)
- timeValue: Type: Time
Type: Void
Writes a field name and value pair using the specified field name and time value in the ISO-8601 format.
public Void writeTimeField(String fieldName, Time timeValue)
Type: Void