Class JsonObject
- All Implemented Interfaces:
AutoCloseable
Load, navigate, create, modify, search, sort, and emit JSON objects.
Chilkat.JsonObject provides DOM-style access to JSON objects.
It can load, inspect, modify, create, search, sort, emit, and save JSON data.
It supports path-based access, index-based member access, automatic creation
of nested paths, object and array references, Firebase-style updates, record
searches, date/time conversion, binary data encoding, variable substitution,
and optional secure secret resolution.
Load and emit JSON
Load JSON from strings, files, buffers, or Chilkat objects, then emit the result as compact or pretty-formatted JSON.
Path-based navigation
Read and update nested values using JSON paths, with support for automatically creating missing object or array paths.
Member access
Access object members by name or index, inspect member types, retrieve values, and remove or rename members as needed.
Nested objects and arrays
Work directly with child JsonObject and
JsonArray references to navigate and modify complex JSON
structures.
Search and transform
Search records, sort object members, perform Firebase-style updates, and prepare JSON for API requests or application storage.
Special value handling
Handle date/time values, binary data encodings, exact numeric text, variable substitution, and secure secret resolution.
Common pattern:
Load or create a JsonObject, navigate named members and nested
paths, retrieve child arrays as JsonArray objects when ordered
lists are encountered, update values as needed, then emit or save the final
JSON. Use JsonObject for named JSON members and
JsonArray for ordered lists.
For an extended overview, see JsonObject Class Overview.
</section>
Instances hold a native Chilkat object: close them with ChilkatObject.close() (try-with-resources) when
done; an unclosed instance is freed when it becomes unreachable.
- See Also:
- Online reference
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddArrayAt(int index, String name)Inserts a new JSON array member namednameat the zero-based member positionindex.voidaddArrayCopyAt(int index, String name, JsonArray jarr)Inserts a new JSON array member namednameat the zero-based member positionindex.voidInserts a new JSON boolean member namednameat the zero-based member positionindex.voidInserts a new JSON number member namednameat the zero-based member positionindex.voidInserts a new JSON null member namednameat the zero-based member positionindex.voidaddNumberAt(int index, String name, String numericStr)Inserts a new JSON number member namednameat the zero-based member positionindex.voidaddObjectAt(int index, String name)Inserts a new JSON object member namednameat the zero-based member positionindex.voidaddObjectCopyAt(int index, String name, JsonObject jsonObj)Inserts a new JSON object member namednameat the zero-based member positionindex.voidaddStringAt(int index, String name, String value)Inserts a new JSON string member namednameat the zero-based member positionindex.appendArray(String name)Appends a new JSON array member namednameto this object.voidappendArray2(String name, JsonArray jarr)Appends a new JSON array member namednameto this object.voidappendArrayCopy(String name, JsonArray jarr)Appends a new JSON array member namednameto this object.voidappendBool(String name, boolean value)Appends a new JSON boolean member namednameto this object.voidAppends a new JSON number member namednameto this object.appendObject(String name)Appends a new JSON object member namednameto this object.voidappendObject2(String name, JsonObject jsonObj)Appends a new JSON object member namednameto this object.voidappendObjectCopy(String name, JsonObject jsonObj)Appends a new JSON object member namednameto this object.voidappendString(String name, String value)Appends a new JSON string member namednameto this object.voidappendStringArray(String name, StringTable values)Appends a new JSON array member namednameto this object.arrayAt(int index)Returns the JSON array stored in the member at zero-based positionindex.voidUpdatesjarrto reference the JSON array stored at zero-based member positionindexand returnstrueon success.Returns the JSON array atjsonPath.voidUpdatesjarrto reference the JSON array atjsonPathand returnstrueon success.booleanboolAt(int index)Returns the boolean value of the member at zero-based positionindex.booleanReturns the boolean value atjsonPath.voidReads the string value atjsonPath, decodes it usingencoding(for example,base64orhex), and appends the resulting bytes tobd.voidclear()Removes all members from this JSON object, leaving an empty object equivalent to{}.voidcopyRef(JsonObject jsonObj)UpdatesjsonObjso that it references the same JSON object as the caller.voidParses the date/time value atjsonPathand loads the result intodt.voidDeletes the direct member namednamefrom this JSON object.voiddeleteAt(int index)Deletes the member at zero-based positionindex.intdeleteRecords(String arrayPath, String relpath, String value, boolean caseSensitive)Deletes every object record in the array atarrayPathwhose value at relative pathrelpathequals or wildcard-matchesvalue.voidParses the date/time value atjsonPathintodt.emit()Serializes the JSON document rooted at this object and returns the JSON text.voidSerializes this JSON and appends the resulting bytes tobd.voidemitSb(StringBuilder sb)Serializes this JSON and appends the resulting text tosb.emitWithSubs(Hashtable subs, boolean omitEmpty)Serializes the JSON after substituting variables fromsubsinto template strings.findObjectWithMember(String name)Recursively searches this JSON subtree for the first JSON object containing a direct member namedname.voidfindObjectWithMember2(String name, JsonObject jsonObj)Recursively searches this JSON subtree for the first object containing a direct member namedname.findRecord(String arrayPath, String relPath, String value, boolean caseSensitive)Searches the JSON array atarrayPathfor the first object whose value at relative pathrelPathequals or wildcard-matchesvalue.voidfindRecord2(String arrayPath, String relPath, String value, boolean caseSensitive, JsonObject jsonObj)Searches the JSON array atarrayPathusing the same matching rules asFindRecord.findRecordString(String arrayPath, String relPath, String value, boolean caseSensitive, String retRelPath)Searches the JSON array atarrayPathfor the first record whoserelPathvalue equals or wildcard-matchesvalue, then returns the value atretRelPathfrom that same record as a string.voidfirebaseApplyEvent(String name, String data)Applies a Firebase Realtime Database event to this JSON object.voidfirebasePatch(String jsonPath, String jsonData)Applies Firebase-style patch semantics atjsonPath.voidfirebasePut(String jsonPath, String value)Applies Firebase-style put semantics atjsonPath, replacing or inserting the value at that path.Specifies the character used to separate object-member names in Chilkat JSON paths.Returns aJsonObjectreference to the root object of the JSON document containing this object.voidgetDocRoot2(JsonObject docRoot)UpdatesdocRootto reference the root object of the JSON document containing the caller and returnstrueon success.booleanControls whether emitted JSON is compact or pretty-printed.booleanControls line endings when pretty-printed JSON is emitted (EmitCompact =).falsebooleanEnables automatic resolution of Chilkat secret specification strings for supported string-setting methods.intgetI()Supplies the integer substituted foriwhen a JSON path contains an array index such as[i].intgetJ()Supplies the integer substituted forjwhen a JSON path contains[j].intgetK()Supplies the integer substituted forkwhen a JSON path contains[k].booleanIftrue, member names are converted to lowercase while JSON is loaded byLoad,LoadBd,LoadSb, orLoadFile.Specifies a path prefix automatically prepended to JSON paths passed to path-based methods such asStringOf,ObjectOf,UpdateString,SetBoolOf, andSizeOfArray.intgetSize()Returns the number of direct name/value members in this JSON object.booleanWhenStrictis true, the Load methods first check that the data is well-formed JSON.Provides a catch-all string for uncommon, implementation-specific options.booleanReturnstrueif a value exists atjsonPath; otherwise returnsfalse.intReturns the zero-based position of the direct member namedname, or-1if that member name is not found.intintAt(int index)Returns the integer value of the member at zero-based positionindex.intReturns the integer value atjsonPath.booleanisNullAt(int index)Returnstrueif the member at zero-based positionindexhas the JSON valuenull; otherwise returnsfalse.booleanReturnstrueif the value atjsonPathis the JSON literalnull; otherwise returnsfalse.intjsonTypeOf(String jsonPath)Returns an integer identifying the JSON type of the value atjsonPath.voidParses the JSON text injsonand loads the parsed data into this object for DOM-style access and modification.voidParses JSON from the bytes contained inbdand loads it into this object.voidReads JSON text from the file atpath, parses it, and loads the result into this object.voidloadPredefined(String name)Loads this object from the predefined JSON document identified byname.voidloadSb(StringBuilder sb)Parses JSON from the current contents ofsband loads it into this object.voidmakeCopy(JsonObject json)Copies this JSON object intojson.voidmoveMember(int fromIndex, int toIndex)Moves the direct member at zero-based positionfromIndextotoIndex.nameAt(int index)Returns the name of the member at zero-based positionindex.voidnewArrayOf(String path, String jArr)Creates a JSON array atpathand loads that array from the JSON text injArr.voidnewObjectOf(String path, String jObj)Creates a JSON object atpathand loads that object from the JSON text injObj.objectAt(int index)Returns the JSON object stored in the member at zero-based positionindex.voidobjectAt2(int index, JsonObject jsonObj)UpdatesjsonObjto reference the JSON object stored at zero-based member positionindexand returnstrueon success.Returns the JSON object atjsonPath.voidobjectOf2(String jsonPath, JsonObject jsonObj)UpdatesjsonObjto reference the JSON object atjsonPathand returnstrueon success.voidStores this JSON document in Chilkat's internal global collection of predefined JSON documents undername.voidRenames the direct memberoldNametonewName.voidRenames the member at zero-based positionindextoname.voidsetBoolAt(int index, boolean value)Sets the member at zero-based positionindexto a JSON boolean value.voidSets the value atjsonPathto a JSON boolean value.voidsetDelimiterChar(String value)Sets theDelimiterCharproperty; seegetDelimiterChar().voidsetEmitCompact(boolean value)Sets theEmitCompactproperty; seegetEmitCompact().voidsetEmitCrLf(boolean value)Sets theEmitCrLfproperty; seegetEmitCrLf().voidsetEnableSecrets(boolean value)Sets theEnableSecretsproperty; seegetEnableSecrets().voidsetI(int value)Sets theIproperty; seegetI().voidsetIntAt(int index, int value)Sets the member at zero-based positionindexto a JSON number value.voidSets the value atjsonPathto an integer JSON number.voidsetJ(int value)Sets theJproperty; seegetJ().voidsetK(int value)Sets theKproperty; seegetK().voidsetLowerCaseNames(boolean value)Sets theLowerCaseNamesproperty; seegetLowerCaseNames().voidsetNullAt(int index)Sets the member at zero-based positionindexto a JSON null value.voidSets the value atjsonPathto a JSON null value.voidsetNumberAt(int index, String value)Sets the member at zero-based positionindexto a JSON number value.voidsetNumberOf(String jsonPath, String value)Sets the value atjsonPathto a JSON number value.voidsetPathPrefix(String value)Sets thePathPrefixproperty; seegetPathPrefix().voidsetStrict(boolean value)Sets theStrictproperty; seegetStrict().voidsetStringAt(int index, String value)Sets the member at zero-based positionindexto a JSON string value.voidsetStringOf(String jsonPath, String value)Sets the value atjsonPathto a JSON string value.voidsetUncommonOptions(String value)Sets theUncommonOptionsproperty; seegetUncommonOptions().intsizeOfArray(String jsonPath)Returns the number of elements in the JSON array atjsonPath.voidsort(boolean ascending, boolean caseSensitive)Sorts this object's direct members by member name.stringAt(int index)Returns the string value of the member at zero-based positionindex.Returns the value atjsonPathas text.booleanstringOfEquals(String jsonPath, String value, boolean caseSensitive)Returnstrueif the textual value atjsonPathequalsvalueaccording to thecaseSensitivesetting; otherwise returnsfalse.voidstringOfSb(String jsonPath, StringBuilder sb)Retrieves the value atjsonPathas text and appends it tosb.voidswap(int index1, int index2)Swaps the positions of the direct members at zero-based indexesindex1andindex2.inttypeAt(int index)Returns an integer identifying the JSON type of the member at zero-based positionindex.longReturns the unsigned integer value atjsonPath.voidUpdates the value atjsonPathto a JSON string value, or creates the member and any missing path components as needed.voidupdateBool(String jsonPath, boolean value)Updates the value atjsonPathto a JSON boolean value, or creates the member and any missing path components as needed.voidUpdates the value atjsonPathto a JSON number value, or creates the member and any missing path components as needed.voidupdateNewArray(String jsonPath)Creates or replaces the value atjsonPathwith a new empty JSON array.voidupdateNewObject(String jsonPath)Creates or replaces the value atjsonPathwith a new empty JSON object.voidupdateNull(String jsonPath)Updates the value atjsonPathto a JSON null value, or creates the member and any missing path components as needed.voidupdateNumber(String jsonPath, String numericStr)Updates the value atjsonPathto a JSON number value, or creates the member and any missing path components as needed.voidupdateSb(String jsonPath, StringBuilder sb)Updates the value atjsonPathto a JSON string value, or creates the member and any missing path components as needed.voidupdateString(String jsonPath, String value)Updates the value atjsonPathto a JSON string value, or creates the member and any missing path components as needed.voidupdateUInt(String jsonPath, long value)Updates the value atjsonPathto a JSON number value, or creates the member and any missing path components as needed.voidSerializes this JSON and writes it to the file atpath.Methods inherited from class com.chilkatsoft.chilkat2.ChilkatObject
close, getDebugLogFilePath, getLastErrorHtml, getLastErrorText, getLastErrorXml, getLastMethodSuccess, getVerboseLogging, getVersion, isClosed, setDebugLogFilePath, setLastMethodSuccess, setVerboseLogging, toString
-
Constructor Details
-
JsonObject
public JsonObject()Creates a newJsonObjectobject.
-
-
Method Details
-
getDelimiterChar
Specifies the character used to separate object-member names in Chilkat JSON paths. The default is.. Set it to/for Firebase-style paths. This property should contain exactly one character.Arrays in paths: Array indexes continue to use square brackets, such as
orders[0].id. If a member name itself contains a path-separator character, quote that path component with double quotes.- Returns:
- the value of the
DelimiterCharproperty
-
setDelimiterChar
Sets theDelimiterCharproperty; seegetDelimiterChar().- Parameters:
value- the new value (notnull)
-
getEmitCompact
public boolean getEmitCompact()Controls whether emitted JSON is compact or pretty-printed. The default istrue.Emit a compact representation with no extra formatting whitespace.trueEmit indented, human-readable JSON.falseJSON semantics: Formatting whitespace does not change the JSON data. Use compact output for transport/storage and pretty output for diagnostics or human review.
- Returns:
- the value of the
EmitCompactproperty
-
setEmitCompact
public void setEmitCompact(boolean value)Sets theEmitCompactproperty; seegetEmitCompact().- Parameters:
value- the new value
-
getEmitCrLf
public boolean getEmitCrLf()Controls line endings when pretty-printed JSON is emitted (EmitCompact =). The default isfalsetrue.Use CRLF line endings.trueUse LF line endings.falseCompact output: This setting has no effect when
EmitCompactistruebecause compact JSON is emitted without formatting line breaks.- Returns:
- the value of the
EmitCrLfproperty
-
setEmitCrLf
public void setEmitCrLf(boolean value)Sets theEmitCrLfproperty; seegetEmitCrLf().- Parameters:
value- the new value
-
getEnableSecrets
public boolean getEnableSecrets()Enables automatic resolution of Chilkat secret specification strings for supported string-setting methods. The default isfalse. When enabled, a value beginning with!!can identify a credential stored in Windows Credential Manager or Apple Keychain instead of embedding the literal secret in application code.Secret specification format:
!![appName|]service[|domain]|username.This feature applies to
AddStringAt,AppendString,SetStringAt,SetStringOf,UpdateSb, andUpdateString.Security: Secret resolution changes where the string value comes from; the resulting JSON member still contains the resolved value. Avoid emitting or logging JSON that contains credentials unless that exposure is explicitly intended.
- Returns:
- the value of the
EnableSecretsproperty
-
setEnableSecrets
public void setEnableSecrets(boolean value)Sets theEnableSecretsproperty; seegetEnableSecrets().- Parameters:
value- the new value
-
getI
public int getI()Supplies the integer substituted foriwhen a JSON path contains an array index such as[i]. This is useful for loop-based navigation without constructing a new path string for every iteration.Related properties: The
JandKproperties provide the same substitution behavior for[j]and[k].- Returns:
- the value of the
Iproperty
-
setI
public void setI(int value)Sets theIproperty; seegetI().- Parameters:
value- the new value
-
getJ
public int getJ()Supplies the integer substituted forjwhen a JSON path contains[j]. It is commonly used with nested-array paths such asmatrix[i][j].- Returns:
- the value of the
Jproperty
-
setJ
public void setJ(int value)Sets theJproperty; seegetJ().- Parameters:
value- the new value
-
getK
public int getK()Supplies the integer substituted forkwhen a JSON path contains[k]. It can be combined withIandJfor deeper nested-array traversal.- Returns:
- the value of the
Kproperty
-
setK
public void setK(int value)Sets theKproperty; seegetK().- Parameters:
value- the new value
-
getLowerCaseNames
public boolean getLowerCaseNames()Iftrue, member names are converted to lowercase while JSON is loaded byLoad,LoadBd,LoadSb, orLoadFile. The default isfalse.Important: This changes member names in the parsed document; it is not merely a case-insensitive lookup mode. Use it only when normalizing names is intentional.
- Returns:
- the value of the
LowerCaseNamesproperty
-
setLowerCaseNames
public void setLowerCaseNames(boolean value)Sets theLowerCaseNamesproperty; seegetLowerCaseNames().- Parameters:
value- the new value
-
getPathPrefix
Specifies a path prefix automatically prepended to JSON paths passed to path-based methods such asStringOf,ObjectOf,UpdateString,SetBoolOf, andSizeOfArray. The default is the empty string.Use case: Set a prefix when many operations target the same nested object. The individual method calls can then use paths relative to that prefix.
- Returns:
- the value of the
PathPrefixproperty
-
setPathPrefix
Sets thePathPrefixproperty; seegetPathPrefix().- Parameters:
value- the new value (notnull)
-
getSize
public int getSize()Returns the number of direct name/value members in this JSON object. Nested members inside child objects are not included.JSON objects and order: RFC 8259 defines a JSON object as an unordered collection of name/value pairs. Chilkat preserves a member order so index-based APIs and deterministic emission are possible, but interoperable application logic should generally use member names rather than depend on object order.
- Returns:
- the value of the
Sizeproperty (read-only)
-
getStrict
public boolean getStrict()WhenStrictis true, the Load methods first check that the data is well-formed JSON. If it is not, the load fails and the contents of this JsonObject are left unchanged. The default isfalse.This applies to
,load(String),loadSb(StringBuilder),loadBd(BinData)andloadFile(String).loadPredefined(String)Chilkat's JSON parser is deliberately tolerant. By default it can accept text that is not well-formed, succeed, and leave an empty or partially populated document. That is convenient when the goal is a best-effort parse of imperfect input, but it is the wrong behavior when a silently missing member changes what the application does. A single missing comma, for example, can cause the members after it to be dropped while the load still reports success.
Set
Stricttotruefor JSON carrying configuration, credentials, or security parameters, where a member that quietly failed to load would be acted on as though it had never been specified.Note: The default is
falseso that existing applications are unaffected. When a strict load is rejected, this JsonObject keeps whatever it held before the call, so a failed reload never leaves the object empty.- Returns:
- the value of the
Strictproperty
-
setStrict
public void setStrict(boolean value)Sets theStrictproperty; seegetStrict().- Parameters:
value- the new value
-
getUncommonOptions
Provides a catch-all string for uncommon, implementation-specific options. The default is the empty string and it should normally remain empty.Recommendation: Do not invent option keywords. Set this property only when a specific
JsonObjectoption is documented by Chilkat or provided by Chilkat support.- Returns:
- the value of the
UncommonOptionsproperty
-
setUncommonOptions
Sets theUncommonOptionsproperty; seegetUncommonOptions().- Parameters:
value- the new value (notnull)
-
addArrayAt
Inserts a new JSON array member namednameat the zero-based member positionindex. The new array is empty.0Insert as the first member.-1Append as the last member.nInsert at zero-based position n.Member name vs. JSON path:
nameis a direct member name, not a JSON path. Use anUpdate*orSet*Ofmethod when addressing a nested value by path.- Parameters:
index- theindexargumentname- thenameargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
addArrayCopyAt
Inserts a new JSON array member namednameat the zero-based member positionindex. The array value is copied fromjarr; subsequent changes to the source array do not modify the inserted copy.0Insert as the first member.-1Append as the last member.nInsert at zero-based position n.Member name vs. JSON path:
nameis a direct member name, not a JSON path. Use anUpdate*orSet*Ofmethod when addressing a nested value by path.- Parameters:
index- theindexargumentname- thenameargument (notnull)jarr- thejarrargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
addBoolAt
Inserts a new JSON boolean member namednameat the zero-based member positionindex. The value is taken fromvalue.0Insert as the first member.-1Append as the last member.nInsert at zero-based position n.Member name vs. JSON path:
nameis a direct member name, not a JSON path. Use anUpdate*orSet*Ofmethod when addressing a nested value by path.- Parameters:
index- theindexargumentname- thenameargument (notnull)value- thevalueargument- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
addIntAt
Inserts a new JSON number member namednameat the zero-based member positionindex. The integervalueis emitted as a JSON number, not as a quoted string.0Insert as the first member.-1Append as the last member.nInsert at zero-based position n.Member name vs. JSON path:
nameis a direct member name, not a JSON path. Use anUpdate*orSet*Ofmethod when addressing a nested value by path.- Parameters:
index- theindexargumentname- thenameargument (notnull)value- thevalueargument- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
addNullAt
Inserts a new JSON null member namednameat the zero-based member positionindex.0Insert as the first member.-1Append as the last member.nInsert at zero-based position n.Member name vs. JSON path:
nameis a direct member name, not a JSON path. Use anUpdate*orSet*Ofmethod when addressing a nested value by path.- Parameters:
index- theindexargumentname- thenameargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
addNumberAt
Inserts a new JSON number member namednameat the zero-based member positionindex. ThenumericStrargument supplies the exact JSON numeric text to store.0Insert as the first member.-1Append as the last member.nInsert at zero-based position n.Member name vs. JSON path:
nameis a direct member name, not a JSON path. Use anUpdate*orSet*Ofmethod when addressing a nested value by path.Exact numeric text: Use this method when lexical form or precision matters, for example12345678901234567890,1.2500, or scientific notation. The supplied text must be valid JSON number syntax; JSON does not permitNaNor infinity.- Parameters:
index- theindexargumentname- thenameargument (notnull)numericStr- thenumericStrargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
addObjectAt
Inserts a new JSON object member namednameat the zero-based member positionindex. The new object is empty.0Insert as the first member.-1Append as the last member.nInsert at zero-based position n.Member name vs. JSON path:
nameis a direct member name, not a JSON path. Use anUpdate*orSet*Ofmethod when addressing a nested value by path.- Parameters:
index- theindexargumentname- thenameargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
addObjectCopyAt
Inserts a new JSON object member namednameat the zero-based member positionindex. The object value is copied fromjsonObj; the inserted value is independent of the source.0Insert as the first member.-1Append as the last member.nInsert at zero-based position n.Member name vs. JSON path:
nameis a direct member name, not a JSON path. Use anUpdate*orSet*Ofmethod when addressing a nested value by path.- Parameters:
index- theindexargumentname- thenameargument (notnull)jsonObj- thejsonObjargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
addStringAt
Inserts a new JSON string member namednameat the zero-based member positionindex. The value is stored as a JSON string and is escaped as needed when emitted.0Insert as the first member.-1Append as the last member.nInsert at zero-based position n.Member name vs. JSON path:
nameis a direct member name, not a JSON path. Use anUpdate*orSet*Ofmethod when addressing a nested value by path.- Parameters:
index- theindexargumentname- thenameargument (notnull)value- thevalueargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
appendArray
Appends a new JSON array member namednameto this object. The newly appended array is empty and the returnedJsonArrayreferences that array in this document, so changes made through it modify the same JSON tree.Member name vs. JSON path:
nameis a direct member name. It is not interpreted as a JSON path. Use the correspondingUpdate*method when a nested path should be addressed or created.- Parameters:
name- thenameargument (notnull)- Returns:
- a new
JsonArrayowned by the caller (nevernull); close it when done - Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
appendArray2
Appends a new JSON array member namednameto this object. A new empty array is created andjarris updated to reference it. The method returnstrueon success.Member name vs. JSON path:
nameis a direct member name. It is not interpreted as a JSON path. Use the correspondingUpdate*method when a nested path should be addressed or created.- Parameters:
name- thenameargument (notnull)jarr- thejarrargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
appendArrayCopy
Appends a new JSON array member namednameto this object. The array is copied fromjarr, so the appended array is independent of the source array.Member name vs. JSON path:
nameis a direct member name. It is not interpreted as a JSON path. Use the correspondingUpdate*method when a nested path should be addressed or created.- Parameters:
name- thenameargument (notnull)jarr- thejarrargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
appendBool
Appends a new JSON boolean member namednameto this object. The value is taken fromvalue.Member name vs. JSON path:
nameis a direct member name. It is not interpreted as a JSON path. Use the correspondingUpdate*method when a nested path should be addressed or created.- Parameters:
name- thenameargument (notnull)value- thevalueargument- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
appendInt
Appends a new JSON number member namednameto this object. The integer value is stored as a JSON number.Member name vs. JSON path:
nameis a direct member name. It is not interpreted as a JSON path. Use the correspondingUpdate*method when a nested path should be addressed or created.- Parameters:
name- thenameargument (notnull)value- thevalueargument- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
appendObject
Appends a new JSON object member namednameto this object. The newly appended object is empty and the returnedJsonObjectreferences that object in this document.Member name vs. JSON path:
nameis a direct member name. It is not interpreted as a JSON path. Use the correspondingUpdate*method when a nested path should be addressed or created.- Parameters:
name- thenameargument (notnull)- Returns:
- a new
JsonObjectowned by the caller (nevernull); close it when done - Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
appendObject2
Appends a new JSON object member namednameto this object. A new empty object is created andjsonObjis updated to reference it. The method returnstrueon success.Member name vs. JSON path:
nameis a direct member name. It is not interpreted as a JSON path. Use the correspondingUpdate*method when a nested path should be addressed or created.- Parameters:
name- thenameargument (notnull)jsonObj- thejsonObjargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
appendObjectCopy
Appends a new JSON object member namednameto this object. The object is copied fromjsonObj, so the appended object is independent of the source object.Member name vs. JSON path:
nameis a direct member name. It is not interpreted as a JSON path. Use the correspondingUpdate*method when a nested path should be addressed or created.- Parameters:
name- thenameargument (notnull)jsonObj- thejsonObjargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
appendString
Appends a new JSON string member namednameto this object. The value is JSON-escaped as needed when emitted.Member name vs. JSON path:
nameis a direct member name. It is not interpreted as a JSON path. Use the correspondingUpdate*method when a nested path should be addressed or created.- Parameters:
name- thenameargument (notnull)value- thevalueargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
appendStringArray
Appends a new JSON array member namednameto this object. The array is populated with the strings contained invalues.Member name vs. JSON path:
nameis a direct member name. It is not interpreted as a JSON path. Use the correspondingUpdate*method when a nested path should be addressed or created.- Parameters:
name- thenameargument (notnull)values- thevaluesargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
arrayAt
Returns the JSON array stored in the member at zero-based positionindex. The returnedJsonArrayreferences the existing array in the same document; it is not a detached copy.Type requirement: The member at
indexmust be an array. UseTypeAtwhen the member type is not already known.- Parameters:
index- theindexargument- Returns:
- a new
JsonArrayowned by the caller (nevernull); close it when done - Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
arrayAt2
Updatesjarrto reference the JSON array stored at zero-based member positionindexand returnstrueon success.- Parameters:
index- theindexargumentjarr- thejarrargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
arrayOf
Returns the JSON array atjsonPath. The returnedJsonArrayreferences the existing array in the same document, so modifications through it are reflected in the parent JSON.JSON paths: Paths are relative to this object and may include object-member separators and array indexes, for example
orders[0].items.- Parameters:
jsonPath- thejsonPathargument (notnull)- Returns:
- a new
JsonArrayowned by the caller, ornullif not found (no exception is thrown in that case); close it when done
-
arrayOf2
Updatesjarrto reference the JSON array atjsonPathand returnstrueon success.- Parameters:
jsonPath- thejsonPathargument (notnull)jarr- thejarrargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
boolAt
public boolean boolAt(int index)Returns the boolean value of the member at zero-based positionindex.Indexing: Member indexes are based on the order maintained by this
JsonObjectinstance. JSON objects are semantically unordered, so application protocols should normally identify values by member name rather than by position.- Parameters:
index- theindexargument- Returns:
- the result; this method never throws
ChilkatException
-
boolOf
Returns the boolean value atjsonPath. The path is evaluated relative to thisJsonObject, after applyingPathPrefixif one is set.- Parameters:
jsonPath- thejsonPathargument (notnull)- Returns:
- the result; this method never throws
ChilkatException
-
bytesOf
Reads the string value atjsonPath, decodes it usingencoding(for example,base64orhex), and appends the resulting bytes tobd.Binary-in-JSON convention: The JSON member itself is text. The
encodingargument tells Chilkat how that text represents the original bytes.- Parameters:
jsonPath- thejsonPathargument (notnull)encoding- theencodingargument (notnull)bd- thebdargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
clear
public void clear()Removes all members from this JSON object, leaving an empty object equivalent to{}. -
copyRef
UpdatesjsonObjso that it references the same JSON object as the caller. No JSON data is copied.Shared state: After this call, modifications through either reference affect the same underlying JSON object.
- Parameters:
jsonObj- thejsonObjargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
dateOf
Parses the date/time value atjsonPathand loads the result intodt. Recognized forms include ISO 8601 timestamps (for example,2009-11-04T19:55:41Z), RFC 822-style date/time strings, and Unix timestamp integers.JSON has no native date type: Dates in JSON are application conventions, usually represented as strings or numbers. This method recognizes common conventions and converts them to
CkDateTime.- Parameters:
jsonPath- thejsonPathargument (notnull)dt- thedtargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
delete
Deletes the direct member namednamefrom this JSON object.Not a path:
nameis a member name, not a JSON path. Use a path-based operation when deleting or replacing a nested value requires navigation first.- Parameters:
name- thenameargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
deleteAt
public void deleteAt(int index)Deletes the member at zero-based positionindex. Members after the deleted position shift toward the beginning.- Parameters:
index- theindexargument- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
deleteRecords
Deletes every object record in the array atarrayPathwhose value at relative pathrelpathequals or wildcard-matchesvalue. ThecaseSensitiveargument controls matching. Returns the number of records deleted.- Parameters:
arrayPath- thearrayPathargument (notnull)relpath- therelpathargument (notnull)value- thevalueargument (notnull)caseSensitive- thecaseSensitiveargument- Returns:
- the result (see
ChilkatObject.getLastMethodSuccess()where the description mentions failure)
-
dtOf
Parses the date/time value atjsonPathintodt. IfbLocalistrue, the destination receives local date/time fields; otherwise it receives UTC/GMT fields. Recognized inputs include ISO 8601 timestamps, RFC 822-style date/time strings, and Unix timestamp integers.- Parameters:
jsonPath- thejsonPathargument (notnull)bLocal- thebLocalargumentdt- thedtargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
emit
Serializes the JSON document rooted at this object and returns the JSON text. Formatting is controlled byEmitCompactand, for pretty output,EmitCrLf.Object member order: Chilkat emits members in its maintained order, but JSON object ordering is not semantically significant under RFC 8259.
- Returns:
- the result (never
null) - Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
emitBd
Serializes this JSON and appends the resulting bytes tobd.Append behavior: Existing data in the destination
BinDatais preserved.- Parameters:
bd- thebdargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
emitSb
Serializes this JSON and appends the resulting text tosb. Formatting followsEmitCompactandEmitCrLf.Append behavior: Existing text in the destination
StringBuilderis preserved; the emitted JSON is added after it.- Parameters:
sb- thesbargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
emitWithSubs
Serializes the JSON after substituting variables fromsubsinto template strings. A placeholder such as{$name}is replaced by the corresponding hashtable value. Prefixing the variable name withi., as in{$i.count}, emits the substituted value as a JSON integer instead of a quoted string.If
omitEmptyistrue, members whose substituted result is an empty string or empty array are omitted from the emitted JSON.Template reuse: This method does not require rebuilding the JSON template. It is commonly paired with
PredefineandLoadPredefinedwhen the same JSON shape is emitted repeatedly with different values.- Parameters:
subs- thesubsargument (notnull)omitEmpty- theomitEmptyargument- Returns:
- the result (never
null) - Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
findObjectWithMember
Recursively searches this JSON subtree for the first JSON object containing a direct member namedname. Returns that object, ornullif no matching object is found.- Parameters:
name- thenameargument (notnull)- Returns:
- a new
JsonObjectowned by the caller, ornullif not found (no exception is thrown in that case); close it when done
-
findObjectWithMember2
Recursively searches this JSON subtree for the first object containing a direct member namedname. On success,jsonObjis updated to reference the matching object and the method returnstrue.- Parameters:
name- thenameargument (notnull)jsonObj- thejsonObjargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
findRecord
public JsonObject findRecord(String arrayPath, String relPath, String value, boolean caseSensitive)Searches the JSON array atarrayPathfor the first object whose value at relative pathrelPathequals or wildcard-matchesvalue. ThecaseSensitiveargument controls string comparison. Returns the matching record object.Wildcard matching: The search value may contain
*to match zero or more characters.relPathis evaluated relative to each record object in the array.- Parameters:
arrayPath- thearrayPathargument (notnull)relPath- therelPathargument (notnull)value- thevalueargument (notnull)caseSensitive- thecaseSensitiveargument- Returns:
- a new
JsonObjectowned by the caller, ornullif not found (no exception is thrown in that case); close it when done
-
findRecord2
public void findRecord2(String arrayPath, String relPath, String value, boolean caseSensitive, JsonObject jsonObj)Searches the JSON array atarrayPathusing the same matching rules asFindRecord. On success,jsonObjis updated to reference the first matching record and the method returnstrue.Reference semantics: The destination references the record in the original JSON document; changes made through
jsonObjmodify that record.- Parameters:
arrayPath- thearrayPathargument (notnull)relPath- therelPathargument (notnull)value- thevalueargument (notnull)caseSensitive- thecaseSensitiveargumentjsonObj- thejsonObjargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
findRecordString
public String findRecordString(String arrayPath, String relPath, String value, boolean caseSensitive, String retRelPath)Searches the JSON array atarrayPathfor the first record whoserelPathvalue equals or wildcard-matchesvalue, then returns the value atretRelPathfrom that same record as a string.Typical use: This is useful for lookups such as “find the record where
NameisAdvertisingand return itsId.” The*wildcard may be used invalue.- Parameters:
arrayPath- thearrayPathargument (notnull)relPath- therelPathargument (notnull)value- thevalueargument (notnull)caseSensitive- thecaseSensitiveargumentretRelPath- theretRelPathargument (notnull)- Returns:
- the result, or
nullif not found (no exception is thrown in that case)
-
firebaseApplyEvent
Applies a Firebase Realtime Database event to this JSON object.nameshould beputorpatch, anddatashould contain event JSON such as{"path":"/","data":{"a":1,"b":2}}.Purpose: This method is useful when maintaining a local JSON representation from Firebase server-sent events:
putreplaces the value at a path, whilepatchupdates individual child keys.- Parameters:
name- thenameargument (notnull)data- thedataargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
firebasePatch
Applies Firebase-style patch semantics atjsonPath.jsonDatamust contain a JSON object; each key in that object updates or adds the corresponding key at the target path.Relative path:
jsonPathis relative to thisJsonObject.- Parameters:
jsonPath- thejsonPathargument (notnull)jsonData- thejsonDataargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
firebasePut
Applies Firebase-style put semantics atjsonPath, replacing or inserting the value at that path.valueis JSON text and may represent an object, array, number, boolean,null, or a quoted JSON string.Quoted strings: To store a string through this method,
valuemust contain a valid JSON string literal, including its surrounding double quotes. UseUpdateStringwhen you already have an ordinary application string.- Parameters:
jsonPath- thejsonPathargument (notnull)value- thevalueargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
getDocRoot
Returns aJsonObjectreference to the root object of the JSON document containing this object. This can be called from any nested object reference.Shared document lifetime: Nested
JsonObjectreferences share the same underlying JSON document. The document remains available while at least one such reference is retained by the application.- Returns:
- a new
JsonObjectowned by the caller (nevernull); close it when done - Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
getDocRoot2
UpdatesdocRootto reference the root object of the JSON document containing the caller and returnstrueon success.Reference semantics: The destination is another reference into the same underlying document; it is not a copy.
- Parameters:
docRoot- thedocRootargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
hasMember
Returnstrueif a value exists atjsonPath; otherwise returnsfalse.Missing vs. null: A member whose JSON value is
nullstill exists. UseIsNullOfto test specifically for JSONnull.- Parameters:
jsonPath- thejsonPathargument (notnull)- Returns:
- the result; this method never throws
ChilkatException
-
indexOf
Returns the zero-based position of the direct member namedname, or-1if that member name is not found.Not a path:
nameis searched only among the direct members of this object.- Parameters:
name- thenameargument (notnull)- Returns:
- the result (see
ChilkatObject.getLastMethodSuccess()where the description mentions failure)
-
intAt
public int intAt(int index)Returns the integer value of the member at zero-based positionindex.Indexing: Member indexes are based on the order maintained by this
JsonObjectinstance. JSON objects are semantically unordered, so application protocols should normally identify values by member name rather than by position.- Parameters:
index- theindexargument- Returns:
- the result (see
ChilkatObject.getLastMethodSuccess()where the description mentions failure)
-
intOf
Returns the integer value atjsonPath. The path is evaluated relative to thisJsonObject, after applyingPathPrefixif one is set.Large numbers: Use
StringOfor the exact numeric-text APIs when a JSON integer may exceed the range of the language binding's integer type.- Parameters:
jsonPath- thejsonPathargument (notnull)- Returns:
- the result (see
ChilkatObject.getLastMethodSuccess()where the description mentions failure)
-
isNullAt
public boolean isNullAt(int index)Returnstrueif the member at zero-based positionindexhas the JSON valuenull; otherwise returnsfalse.- Parameters:
index- theindexargument- Returns:
- the result; this method never throws
ChilkatException
-
isNullOf
Returnstrueif the value atjsonPathis the JSON literalnull; otherwise returnsfalse.Null is a value: JSON
nullis different from a missing member and from an empty string. UseHasMemberwhen existence must be tested separately.- Parameters:
jsonPath- thejsonPathargument (notnull)- Returns:
- the result; this method never throws
ChilkatException
-
jsonTypeOf
Returns an integer identifying the JSON type of the value atjsonPath. Returns-1if no member exists at that path.1string2number3object4array5boolean6null- Parameters:
jsonPath- thejsonPathargument (notnull)- Returns:
- the result (see
ChilkatObject.getLastMethodSuccess()where the description mentions failure)
-
load
Parses the JSON text injsonand loads the parsed data into this object for DOM-style access and modification.JSON data model: JSON values are strings, numbers, booleans,
null, objects, or arrays. Object member names should be unique for interoperable JSON; RFC 8259 notes that consumers differ in how duplicate names are handled.- Parameters:
json- thejsonargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
loadBd
Parses JSON from the bytes contained inbdand loads it into this object.- Parameters:
bd- thebdargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
loadFile
Reads JSON text from the file atpath, parses it, and loads the result into this object.- Parameters:
path- thepathargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
loadPredefined
Loads this object from the predefined JSON document identified byname. Predefined documents are created withPredefine.- Parameters:
name- thenameargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
loadSb
Parses JSON from the current contents ofsband loads it into this object.- Parameters:
sb- thesbargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
makeCopy
Copies this JSON object intojson. The destination receives an independent JSON copy rather than another reference to the same underlying object.Copy vs. reference: Use
CopyRefwhen twoJsonObjectinstances should refer to the same JSON object instead of duplicating its data.- Parameters:
json- thejsonargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
moveMember
public void moveMember(int fromIndex, int toIndex)Moves the direct member at zero-based positionfromIndextotoIndex. UsetoIndex = 0to move it first or-1to move it last.- Parameters:
fromIndex- thefromIndexargumenttoIndex- thetoIndexargument- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
nameAt
Returns the name of the member at zero-based positionindex. Use this withSizeandTypeAtto iterate through an object's direct members.- Parameters:
index- theindexargument- Returns:
- the result (never
null) - Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
newArrayOf
Creates a JSON array atpathand loads that array from the JSON text injArr. The supplied text should represent a JSON array.Difference from UpdateNewArray:
UpdateNewArraycreates an empty array.NewArrayOfcreates the array and immediately populates it from JSON text.- Parameters:
path- thepathargument (notnull)jArr- thejArrargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
newObjectOf
Creates a JSON object atpathand loads that object from the JSON text injObj. The supplied text should represent a JSON object.Difference from UpdateNewObject:
UpdateNewObjectcreates an empty object.NewObjectOfcreates the object and immediately populates it from JSON text.- Parameters:
path- thepathargument (notnull)jObj- thejObjargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
objectAt
Returns the JSON object stored in the member at zero-based positionindex. The returnedJsonObjectreferences the existing child object in the same document; changes made through it modify that document.Type requirement: The member at
indexmust be a JSON object. UseTypeAtwhen the type is not already known.- Parameters:
index- theindexargument- Returns:
- a new
JsonObjectowned by the caller (nevernull); close it when done - Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
objectAt2
UpdatesjsonObjto reference the JSON object stored at zero-based member positionindexand returnstrueon success.- Parameters:
index- theindexargumentjsonObj- thejsonObjargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
objectOf
Returns the JSON object atjsonPath. The returned object is a live reference into the same JSON document, not a copy.Relative paths: A path is evaluated relative to the current object. Use
GetDocRootwhen access must start from the document root.- Parameters:
jsonPath- thejsonPathargument (notnull)- Returns:
- a new
JsonObjectowned by the caller, ornullif not found (no exception is thrown in that case); close it when done
-
objectOf2
UpdatesjsonObjto reference the JSON object atjsonPathand returnstrueon success.- Parameters:
jsonPath- thejsonPathargument (notnull)jsonObj- thejsonObjargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
predefine
Stores this JSON document in Chilkat's internal global collection of predefined JSON documents undername. If the name already exists, the predefined value is replaced.Template use: After predefining a document, another
JsonObjectcan load it by name withLoadPredefined.- Parameters:
name- thenameargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
rename
Renames the direct memberoldNametonewName. The member value and its position are otherwise unchanged.JSON interoperability: JSON object member names should be unique. Avoid renaming a member to a name already used by another member unless duplicate names are intentionally required.
- Parameters:
oldName- theoldNameargument (notnull)newName- thenewNameargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
renameAt
Renames the member at zero-based positionindextoname. The member value is not changed.- Parameters:
index- theindexargumentname- thenameargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
setBoolAt
public void setBoolAt(int index, boolean value)Sets the member at zero-based positionindexto a JSON boolean value.- Parameters:
index- theindexargumentvalue- thevalueargument- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
setBoolOf
Sets the value atjsonPathto a JSON boolean value.Set vs. Update: Use
UpdateBoolwhen missing objects or array positions along the path should be created automatically.- Parameters:
jsonPath- thejsonPathargument (notnull)value- thevalueargument- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
setIntAt
public void setIntAt(int index, int value)Sets the member at zero-based positionindexto a JSON number value. The integer is emitted as a JSON number.- Parameters:
index- theindexargumentvalue- thevalueargument- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
setIntOf
Sets the value atjsonPathto an integer JSON number.Set vs. Update: Use
UpdateIntwhen missing objects or array positions along the path should be created automatically.- Parameters:
jsonPath- thejsonPathargument (notnull)value- thevalueargument- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
setNullAt
public void setNullAt(int index)Sets the member at zero-based positionindexto a JSON null value.- Parameters:
index- theindexargument- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
setNullOf
Sets the value atjsonPathto a JSON null value.Set vs. Update: Use
UpdateNullwhen missing objects or array positions along the path should be created automatically.- Parameters:
jsonPath- thejsonPathargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
setNumberAt
Sets the member at zero-based positionindexto a JSON number value. Thevalueargument is the exact textual representation of the JSON number.JSON number syntax: The text may contain an integer, fraction, or exponent. It must be valid JSON number syntax; leading zeros (except for zero itself),
NaN, and infinity are not valid JSON numbers.- Parameters:
index- theindexargumentvalue- thevalueargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
setNumberOf
Sets the value atjsonPathto a JSON number value. Thevalueargument supplies the exact textual form of the JSON number.Set vs. Update: Use
UpdateNumberwhen missing objects or array positions along the path should be created automatically.Precision: Using numeric text avoids an intermediate conversion through a floating-point type and can therefore preserve large integers or application-specific decimal formatting.- Parameters:
jsonPath- thejsonPathargument (notnull)value- thevalueargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
setStringAt
Sets the member at zero-based positionindexto a JSON string value. The string is escaped as required when JSON is emitted.- Parameters:
index- theindexargumentvalue- thevalueargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
setStringOf
Sets the value atjsonPathto a JSON string value. The string is escaped as required when JSON is emitted.Set vs. Update: Use
UpdateStringwhen missing objects or array positions along the path should be created automatically.- Parameters:
jsonPath- thejsonPathargument (notnull)value- thevalueargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
sizeOfArray
Returns the number of elements in the JSON array atjsonPath. Returns-1if the path does not resolve to an existing JSON array.- Parameters:
jsonPath- thejsonPathargument (notnull)- Returns:
- the result (see
ChilkatObject.getLastMethodSuccess()where the description mentions failure)
-
sort
public void sort(boolean ascending, boolean caseSensitive)Sorts this object's direct members by member name.ascendingselects ascending or descending order, andcaseSensitivecontrols how names are compared.JSON semantics: Member ordering is not significant to JSON consumers, but sorting can make emitted JSON deterministic and easier to compare or review.
- Parameters:
ascending- theascendingargumentcaseSensitive- thecaseSensitiveargument
-
stringAt
Returns the string value of the member at zero-based positionindex.Indexing: Member indexes are based on the order maintained by this
JsonObjectinstance. JSON objects are semantically unordered, so application protocols should normally identify values by member name rather than by position.Non-string values:StringOfcan also provide textual representations of scalar JSON values such as numbers, booleans, andnull; use the type-specific methods when the JSON type itself matters.- Parameters:
index- theindexargument- Returns:
- the result (never
null) - Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
stringOf
Returns the value atjsonPathas text. For a JSON string, the string value is returned. Scalar non-string values such as numbers, booleans, andnullare returned using their JSON textual representation.Type-sensitive code: Use
JsonTypeOf,IntOf,BoolOf, orIsNullOfwhen the distinction between JSON types is important.- Parameters:
jsonPath- thejsonPathargument (notnull)- Returns:
- the result, or
nullif not found (no exception is thrown in that case)
-
stringOfEquals
Returnstrueif the textual value atjsonPathequalsvalueaccording to thecaseSensitivesetting; otherwise returnsfalse.- Parameters:
jsonPath- thejsonPathargument (notnull)value- thevalueargument (notnull)caseSensitive- thecaseSensitiveargument- Returns:
- the result; this method never throws
ChilkatException
-
stringOfSb
Retrieves the value atjsonPathas text and appends it tosb.Append behavior: Existing contents of the destination
StringBuilderare preserved.- Parameters:
jsonPath- thejsonPathargument (notnull)sb- thesbargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
swap
public void swap(int index1, int index2)Swaps the positions of the direct members at zero-based indexesindex1andindex2. Member names and values are unchanged.Ordering: JSON object order is not semantically significant, but Chilkat preserves an order for index-based access and emission.
- Parameters:
index1- theindex1argumentindex2- theindex2argument- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
typeAt
public int typeAt(int index)Returns an integer identifying the JSON type of the member at zero-based positionindex. Returns-1if no member exists at that index.1string2number3object4array5boolean6null- Parameters:
index- theindexargument- Returns:
- the result (see
ChilkatObject.getLastMethodSuccess()where the description mentions failure)
-
uIntOf
Returns the unsigned integer value atjsonPath.- Parameters:
jsonPath- thejsonPathargument (notnull)- Returns:
- the result (see
ChilkatObject.getLastMethodSuccess()where the description mentions failure)
-
updateBd
Updates the value atjsonPathto a JSON string value, or creates the member and any missing path components as needed. The bytes inbdare first encoded according toencoding(for example,base64orhex) and the encoded text is stored as the JSON string value.Path-based operation:
jsonPathis interpreted usingDelimiterChar,PathPrefix, and theI/J/Kindex substitutions.Binary data in JSON: JSON has no native byte-array type. Binary content must therefore be represented using a textual encoding agreed upon by the producer and consumer.- Parameters:
jsonPath- thejsonPathargument (notnull)encoding- theencodingargument (notnull)bd- thebdargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
updateBool
Updates the value atjsonPathto a JSON boolean value, or creates the member and any missing path components as needed.Path-based operation:
jsonPathis interpreted usingDelimiterChar,PathPrefix, and theI/J/Kindex substitutions.- Parameters:
jsonPath- thejsonPathargument (notnull)value- thevalueargument- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
updateInt
Updates the value atjsonPathto a JSON number value, or creates the member and any missing path components as needed. The integer value is stored as a JSON number.Path-based operation:
jsonPathis interpreted usingDelimiterChar,PathPrefix, and theI/J/Kindex substitutions.- Parameters:
jsonPath- thejsonPathargument (notnull)value- thevalueargument- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
updateNewArray
Creates or replaces the value atjsonPathwith a new empty JSON array. Missing path components are created automatically as needed.- Parameters:
jsonPath- thejsonPathargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
updateNewObject
Creates or replaces the value atjsonPathwith a new empty JSON object. Missing path components are created automatically as needed.- Parameters:
jsonPath- thejsonPathargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
updateNull
Updates the value atjsonPathto a JSON null value, or creates the member and any missing path components as needed.Path-based operation:
jsonPathis interpreted usingDelimiterChar,PathPrefix, and theI/J/Kindex substitutions.- Parameters:
jsonPath- thejsonPathargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
updateNumber
Updates the value atjsonPathto a JSON number value, or creates the member and any missing path components as needed. ThenumericStrargument is stored as the exact textual representation of the JSON number.Path-based operation:
jsonPathis interpreted usingDelimiterChar,PathPrefix, and theI/J/Kindex substitutions.When to use: UseUpdateNumberinstead ofUpdateIntfor decimal/exponent forms, very large integers, or when preserving exact numeric text is important.- Parameters:
jsonPath- thejsonPathargument (notnull)numericStr- thenumericStrargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
updateSb
Updates the value atjsonPathto a JSON string value, or creates the member and any missing path components as needed. The new string value is taken from the contents ofsb.Path-based operation:
jsonPathis interpreted usingDelimiterChar,PathPrefix, and theI/J/Kindex substitutions.- Parameters:
jsonPath- thejsonPathargument (notnull)sb- thesbargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
updateString
Updates the value atjsonPathto a JSON string value, or creates the member and any missing path components as needed. The supplied string is JSON-escaped as needed.Path-based operation:
jsonPathis interpreted usingDelimiterChar,PathPrefix, and theI/J/Kindex substitutions.Version note: Chilkat versions prior to 9.5.0.68 did not correctly escape all characters for this method. Version 9.5.0.68 and later correct that behavior.- Parameters:
jsonPath- thejsonPathargument (notnull)value- thevalueargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
updateUInt
Updates the value atjsonPathto a JSON number value, or creates the member and any missing path components as needed. The unsigned integer is stored as a JSON number.Path-based operation:
jsonPathis interpreted usingDelimiterChar,PathPrefix, and theI/J/Kindex substitutions.- Parameters:
jsonPath- thejsonPathargument (notnull)value- thevalueargument (0 .. 4294967295)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
writeFile
Serializes this JSON and writes it to the file atpath. Output formatting followsEmitCompactandEmitCrLf.- Parameters:
path- thepathargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-