JsonArray Chilkat2 Java Reference Documentation
JsonArray
Current Version: 11.7.0
Markdown version of this page for AI tools (v 11.7.0) · all AI docs
Chilkat.JsonArray
Work with JSON arrays as ordered lists containing strings, numbers,
booleans, nulls, objects, arrays, and mixed value types.
Retrieve, insert, replace, delete, or swap values by array index when
processing JSON list data.
Access child
Search arrays of strings or arrays of objects to locate matching values
without manually scanning every element.
Parse date/time values and preserve exact numeric strings when JSON data
contains values that must not be rounded or reformatted.
Produce compact or pretty JSON output after array data has been loaded,
edited, searched, or built programmatically.
For an extended overview, see
JsonArray Class Overview.
Read, modify, search, and emit ordered JSON arrays.
Chilkat.JsonArray is the JSON array companion to
Chilkat.JsonObject. It represents an ordered list of JSON values
and provides index-based methods for reading, inserting, replacing, deleting,
swapping, searching, and emitting array data. It supports scalar values,
nested objects, nested arrays, date/time parsing, exact numeric string
handling, compact or pretty output, and search helpers for arrays of strings
or arrays of objects.
Ordered JSON values
Index-based access
Nested objects and arrays
JsonObject and JsonArray values to
navigate and modify deeper JSON structures.
Search helpers
Date and numeric handling
Emit JSON output
JsonObject to navigate named members and JSON paths, then
use JsonArray to iterate or modify ordered lists found within
the object tree. Retrieve nested objects or arrays as needed, update values
by index, and emit the final JSON in compact or pretty form.
Object Creation
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.JsonArray;
try (JsonArray jarr = new JsonArray()) {
// ... use jarr ...
} catch (ChilkatException e) {
System.out.println(e.getMessage()); // "JsonArray.someMethod failed: <reason>"
System.out.println(e.getLastErrorText()); // the full log of the failed call
}Creates the underlying native Chilkat object. The native library (chilkat2java) is loaded the first time any Chilkat2 object is created; see the README in the download for where it is looked for (-Dchilkat2.library.path, a classpath resource, or java.library.path).
Releases the native object (JsonArray is AutoCloseable, so try-with-resources calls it). Calling it again does nothing; any other method or property accessor called afterwards throws IllegalStateException. An object that is never closed is freed by a background cleaner once it becomes unreachable, but the garbage collector does not see native memory, so closing is the normal path. Objects returned by methods are owned by the caller too.
Returns true once close() has been called.
Errors
A method that fails throws ChilkatException, an unchecked exception carrying getClassName(), getMethodName(), getReason() (one line, also in the message) and getLastErrorText() (the full log, captured at the moment of the failure). The object remains usable. Methods that look something up and find nothing return null instead of throwing (each such method says so), and methods that answer a question (hasMember, isUnlocked, ...) return a plain boolean. Property accessors do not throw for Chilkat reasons.
A null string or object argument throws NullPointerException naming the parameter (except where a method documents that null is accepted), and a string containing U+0000 throws IllegalArgumentException.
Use an object from one thread at a time; it may be handed from one thread to another. The one cross-thread operation is setting setAbortCurrent(true) on an object that is busy in another thread (on the classes that have AbortCurrent). Unlocking: call new Global().unlockBundle("...") once at startup.
Properties
DebugLogFilePath
String getDebugLogFilePath()
void setDebugLogFilePath(String value)
If set to a file path, this property logs the LastErrorText of each Chilkat method or property call to the specified file. This logging helps identify the context and history of Chilkat calls leading up to any crash or hang, aiding in debugging.
Enabling the VerboseLogging property provides more detailed information. This property is mainly used for debugging rare instances where a Chilkat method call causes a hang or crash, which should generally not happen.
Possible causes of hangs include:
- A timeout property set to 0, indicating an infinite timeout.
- A hang occurring within an event callback in the application code.
- An internal bug in the Chilkat code causing the hang.
EmitCompact
boolean getEmitCompact()
void setEmitCompact(boolean value)
Controls whether emitted JSON is compact or pretty-formatted. If true, output contains no unnecessary whitespace and is emitted on a single line. If false, indentation and line breaks are added for readability. The default is true.
EmitCrlf
boolean getEmitCrlf()
void setEmitCrlf(boolean value)
Controls line endings when pretty-formatted JSON is emitted. If true, line breaks use CRLF (
); if false, they use LF (
). The default is true.
EmitCompact is true, the JSON is emitted on one line and this setting has no effect.FindStartIndex
int getFindStartIndex()
void setFindStartIndex(int value)
Specifies the zero-based array index at which FindString and FindObject begin searching. The default value is 0.
n, set this property to n + 1 before the next search to continue with later elements.LastErrorHtml
String getLastErrorHtml()
Provides HTML-formatted information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.
topLastErrorText
String getLastErrorText()
Provides plain text information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.
LastErrorXml
String getLastErrorXml()
Provides XML-formatted information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.
topLastMethodSuccess
boolean getLastMethodSuccess()
void setLastMethodSuccess(boolean value)
Indicates the success or failure of the most recent method call: true means success, false means failure. This property remains unchanged by property setters or getters. This method is present to address challenges in checking for null or Nothing returns in certain programming languages. Note: This property does not apply to methods that return integer values or to boolean-returning methods where the boolean does not indicate success or failure.
Size
int getSize()
Returns the number of values currently contained in the JSON array. Array indexes therefore range from 0 through Size - 1.
VerboseLogging
boolean getVerboseLogging()
void setVerboseLogging(boolean value)
If set to true, then the contents of LastErrorText (or LastErrorXml, or LastErrorHtml) may contain more verbose information. The default value is false. Verbose logging should only be used for debugging. The potentially large quantity of logged information may adversely affect peformance.
Version
String getVersion()
Methods
AddArrayAt
Inserts a new, empty JSON array at zero-based position index. Existing elements at that position and after it are shifted one position toward the end of the array.
0 | Insert as the first array element. |
-1 | Append as the last array element. |
n | Insert at zero-based position n. |
Add*At methods insert a new array element. Use the corresponding Set*At method when replacing an existing element.Throws ChilkatException on failure; e.getLastErrorText() (or the object's getLastErrorText()) explains why, and the object remains usable.
AddArrayAt2
Inserts a new, empty JSON array at zero-based position index and updates jarr to reference the newly inserted array.
0 | Insert as the first array element. |
-1 | Append as the last array element. |
n | Insert at zero-based position n. |
jarr references the inserted array, it can be populated directly without a separate ArrayAt lookup.Throws ChilkatException on failure; e.getLastErrorText() (or the object's getLastErrorText()) explains why, and the object remains usable.
AddBoolAt
Inserts a new JSON boolean value at zero-based position index. Existing elements at that position and after it are shifted one position toward the end of the array.
0 | Insert as the first array element. |
-1 | Append as the last array element. |
n | Insert at zero-based position n. |
Add*At methods insert a new array element. Use the corresponding Set*At method when replacing an existing element.Throws ChilkatException on failure; e.getLastErrorText() (or the object's getLastErrorText()) explains why, and the object remains usable.
AddIntAt
Inserts a new JSON integer value at zero-based position index. Existing elements at that position and after it are shifted one position toward the end of the array.
0 | Insert as the first array element. |
-1 | Append as the last array element. |
n | Insert at zero-based position n. |
Add*At methods insert a new array element. Use the corresponding Set*At method when replacing an existing element.Throws ChilkatException on failure; e.getLastErrorText() (or the object's getLastErrorText()) explains why, and the object remains usable.
AddNullAt
Inserts a JSON null value at zero-based position index. Existing elements at that position and after it are shifted one position toward the end of the array.
0 | Insert as the first array element. |
-1 | Append as the last array element. |
n | Insert at zero-based position n. |
Add*At methods insert a new array element. Use the corresponding Set*At method when replacing an existing element.Throws ChilkatException on failure; e.getLastErrorText() (or the object's getLastErrorText()) explains why, and the object remains usable.
AddNumberAt
Inserts a JSON number at zero-based position index. The numericStr argument supplies the exact JSON numeric text to store. Existing elements at that position and after it are shifted one position toward the end of the array.
0 | Insert as the first array element. |
-1 | Append as the last array element. |
n | Insert at zero-based position n. |
12345678901234567890, 1.2500, or scientific notation. The supplied text must be valid JSON number syntax; JSON does not permit NaN or infinity.Throws ChilkatException on failure; e.getLastErrorText() (or the object's getLastErrorText()) explains why, and the object remains usable.
AddObjectAt
Inserts a new, empty JSON object at zero-based position index. Existing elements at that position and after it are shifted one position toward the end of the array.
0 | Insert as the first array element. |
-1 | Append as the last array element. |
n | Insert at zero-based position n. |
Add*At methods insert a new array element. Use the corresponding Set*At method when replacing an existing element.Throws ChilkatException on failure; e.getLastErrorText() (or the object's getLastErrorText()) explains why, and the object remains usable.
AddObjectAt2
Inserts a new, empty JSON object at zero-based position index and updates json to reference the newly inserted object.
0 | Insert as the first array element. |
-1 | Append as the last array element. |
n | Insert at zero-based position n. |
json references the inserted object, it can be populated directly without a separate ObjectAt lookup.Throws ChilkatException on failure; e.getLastErrorText() (or the object's getLastErrorText()) explains why, and the object remains usable.
AddObjectCopyAt
Inserts an independent copy of jsonObj at zero-based position index. Existing elements at that position and after it are shifted one position toward the end of the array.
0 | Insert as the first array element. |
-1 | Append as the last array element. |
n | Insert at zero-based position n. |
jsonObj do not serve as edits to the inserted array value.Throws ChilkatException on failure; e.getLastErrorText() (or the object's getLastErrorText()) explains why, and the object remains usable.
AddStringAt
Inserts a new JSON string value at zero-based position index. Existing elements at that position and after it are shifted one position toward the end of the array.
0 | Insert as the first array element. |
-1 | Append as the last array element. |
n | Insert at zero-based position n. |
Add*At methods insert a new array element. Use the corresponding Set*At method when replacing an existing element.Throws ChilkatException on failure; e.getLastErrorText() (or the object's getLastErrorText()) explains why, and the object remains usable.
AddUIntAt
Inserts a new JSON unsigned integer value at zero-based position index. Existing elements at that position and after it are shifted one position toward the end of the array.
0 | Insert as the first array element. |
-1 | Append as the last array element. |
n | Insert at zero-based position n. |
Add*At methods insert a new array element. Use the corresponding Set*At method when replacing an existing element.Throws ChilkatException on failure; e.getLastErrorText() (or the object's getLastErrorText()) explains why, and the object remains usable.
AppendArrayItems
Appends copies of all values from jarr to the end of this array, preserving their order.
Throws ChilkatException on failure; e.getLastErrorText() (or the object's getLastErrorText()) explains why, and the object remains usable.
ArrayAt
Returns the nested JSON array stored at zero-based position index.
JsonArray refers to the existing nested array in the same JSON document. Changes made through the returned object modify that nested array.index must be an array. Use TypeAt when the value type is not already known.Throws ChilkatException on failure; e.getLastErrorText() (or the object's getLastErrorText()) explains why, and the object remains usable. The returned object is new and owned by the caller: close it when done (try (...)), or let it be garbage-collected.
ArrayAt2
Updates jarr so that it references the nested JSON array stored at zero-based position index.
jarr modify the existing nested array in the same JSON document.Throws ChilkatException on failure; e.getLastErrorText() (or the object's getLastErrorText()) explains why, and the object remains usable.
BoolAt
Returns the boolean value stored at zero-based position index.
TypeAt when the JSON type at index is not already known.Never throws: false is an answer, not a failure.
Clear
Removes all values from the array, leaving an empty JSON array ([]).
DateAt
Parses the date/time value at zero-based position index and loads the result into dt. Recognized forms include ISO 8601 timestamps (for example, 2009-11-04T19:55:41Z), RFC 822-style date/time strings, and Unix timestamp integers.
Throws ChilkatException on failure; e.getLastErrorText() (or the object's getLastErrorText()) explains why, and the object remains usable.
DeleteAt
Deletes the value at zero-based position index. Elements following the deleted value shift down by one position.
Throws ChilkatException on failure; e.getLastErrorText() (or the object's getLastErrorText()) explains why, and the object remains usable.
DtAt
Parses the date/time value at zero-based position index and loads the result into dt. If bLocal is true, the populated fields represent local time; if false, they represent UTC/GMT. Recognized forms include ISO 8601 timestamps, RFC 822-style date/time strings, and Unix timestamp integers.
Throws ChilkatException on failure; e.getLastErrorText() (or the object's getLastErrorText()) explains why, and the object remains usable.
Emit
Serializes this JSON array and returns the resulting JSON text.
EmitCompact to choose compact versus pretty output. When pretty output is enabled, EmitCrlf selects CRLF or LF line endings.Throws ChilkatException on failure; e.getLastErrorText() (or the object's getLastErrorText()) explains why, and the object remains usable.
EmitSb
Serializes this JSON array into the supplied StringBuilder.
EmitCompact to choose compact versus pretty output. When pretty output is enabled, EmitCrlf selects CRLF or LF line endings.StringBuilder can avoid returning a very large JSON document as a language-native string before passing it to another Chilkat method or writing it to a file.Throws ChilkatException on failure; e.getLastErrorText() (or the object's getLastErrorText()) explains why, and the object remains usable.
FindObject
Searches array elements that are JSON objects and returns the zero-based index of the first object whose direct member name has a value matching value. Returns -1 if no match is found. The value pattern may contain *, which matches zero or more characters. Set caseSensitive to control whether letter case must match.
name identifies a direct member of each object being tested; it is not a JSON path.FindStartIndex, whose default is 0. To continue searching after a match, set FindStartIndex to the previous returned index plus 1.FindString
Searches for the first string array element matching value and returns its zero-based index, or -1 if no match is found. The pattern may contain *, which matches zero or more characters. Set caseSensitive to control whether letter case must match.
FindStartIndex, whose default is 0. To continue searching after a match, set FindStartIndex to the previous returned index plus 1.IntAt
Returns the integer value stored at zero-based position index.
TypeAt when the JSON type at index is not already known.IsNullAt
Returns true if the value at zero-based position index is the JSON value null; otherwise returns false.
null is a distinct JSON value. It is not the same as an empty string, zero, false, an empty object, or an empty array.Never throws: false is an answer, not a failure.
Load
Parses the JSON array text in jsonArray and loads it into this object. The input must represent a JSON array, beginning with [ and ending with ].
JsonArray its own independent JSON document. If the object previously referenced an array nested inside another JSON document, that relationship is discarded. For this reason, call Load/LoadSb on a new JsonArray instance.Throws ChilkatException on failure; e.getLastErrorText() (or the object's getLastErrorText()) explains why, and the object remains usable.
LoadSb
Parses the JSON array contained in sb and loads it into this object. The input must represent a JSON array, beginning with [ and ending with ].
JsonArray its own independent JSON document. If the object previously referenced an array nested inside another JSON document, that relationship is discarded. For this reason, call Load/LoadSb on a new JsonArray instance.Throws ChilkatException on failure; e.getLastErrorText() (or the object's getLastErrorText()) explains why, and the object remains usable.
ObjectAt
Returns the JSON object stored at zero-based position index.
JsonObject refers to the existing object in the same JSON document. Changes made through the returned object modify that nested object.index must be an object. Use TypeAt when the value type is not already known.Throws ChilkatException on failure; e.getLastErrorText() (or the object's getLastErrorText()) explains why, and the object remains usable. The returned object is new and owned by the caller: close it when done (try (...)), or let it be garbage-collected.
ObjectAt2
Updates jsonObj so that it references the JSON object stored at zero-based position index.
jsonObj modify the existing object in the same JSON document.Throws ChilkatException on failure; e.getLastErrorText() (or the object's getLastErrorText()) explains why, and the object remains usable.
SetBoolAt
Replaces the value at zero-based position index with the specified JSON boolean value. The array length and the positions of other elements are unchanged.
Throws ChilkatException on failure; e.getLastErrorText() (or the object's getLastErrorText()) explains why, and the object remains usable.
SetIntAt
Replaces the value at zero-based position index with the specified JSON integer value. The array length and the positions of other elements are unchanged.
Throws ChilkatException on failure; e.getLastErrorText() (or the object's getLastErrorText()) explains why, and the object remains usable.
SetNullAt
Replaces the value at zero-based position index with the JSON value null. The array length and the positions of other elements are unchanged.
Throws ChilkatException on failure; e.getLastErrorText() (or the object's getLastErrorText()) explains why, and the object remains usable.
SetNumberAt
Replaces the value at zero-based position index with a JSON number. The value argument supplies the exact JSON numeric text to store.
NaN or infinity.Throws ChilkatException on failure; e.getLastErrorText() (or the object's getLastErrorText()) explains why, and the object remains usable.
SetStringAt
Replaces the value at zero-based position index with the specified JSON string value. The array length and the positions of other elements are unchanged.
Throws ChilkatException on failure; e.getLastErrorText() (or the object's getLastErrorText()) explains why, and the object remains usable.
SetUIntAt
Replaces the value at zero-based position index with the specified JSON unsigned integer value. The array length and the positions of other elements are unchanged.
Throws ChilkatException on failure; e.getLastErrorText() (or the object's getLastErrorText()) explains why, and the object remains usable.
StringAt
Returns the string value stored at zero-based position index.
TypeAt when the JSON type at index is not already known.Throws ChilkatException on failure; e.getLastErrorText() (or the object's getLastErrorText()) explains why, and the object remains usable.
Swap
Exchanges the values at zero-based positions index1 and index2. The array length does not change.
Throws ChilkatException on failure; e.getLastErrorText() (or the object's getLastErrorText()) explains why, and the object remains usable.
TypeAt
Returns an integer identifying the JSON type of the value at zero-based position index. Returns -1 if no value exists at that index.
1 | string |
2 | number |
3 | object |
4 | array |
5 | boolean |
6 | null |
ObjectAt, ArrayAt, or IntAt for the wrong kind of value.UIntAt
Returns the unsigned integer value stored at zero-based position index.
TypeAt when the JSON type at index is not already known.