Chilkat Examples

ChilkatHOME.NET Core C#Android™AutoItCC#C++Chilkat2-PythonCkPythonClassic ASPDataFlexDelphi ActiveXDelphi DLLGoJavaLianjaMono C#Node.jsObjective-CPHP ActiveXPHP ExtensionPerlPowerBuilderPowerShellPureBasicRubySQL ServerSwift 2Swift 3,4,5...TclUnicode CUnicode C++VB.NETVBScriptVisual Basic 6.0Visual FoxProXojo Plugin

Visual FoxPro Examples

Web API Categories

ASN.1
AWS KMS
AWS Misc
Amazon EC2
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Key Vault
Azure Service Bus
Azure Table Service
Base64
Bounced Email
Box
CAdES
CSR
CSV
Certificates
Cloud Signature CSC
Code Signing
Compression
DKIM / DomainKey
DNS
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
EBICS
ECC
Ed25519
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
GMail SMTP/IMAP/POP
Geolocation
Google APIs
Google Calendar
Google Cloud SQL
Google Cloud Storage
Google Drive
Google Photos
Google Sheets
Google Tasks
Gzip
HTML-to-XML/Text
HTTP

HTTP Misc
IMAP
JSON
JSON Web Encryption (JWE)
JSON Web Signatures (JWS)
JSON Web Token (JWT)
Java KeyStore (JKS)
MHT / HTML Email
MIME
MS Storage Providers
Microsoft Graph
Misc
NTLM
OAuth1
OAuth2
OIDC
Office365
OneDrive
OpenSSL
Outlook
Outlook Calendar
Outlook Contact
PDF Signatures
PEM
PFX/P12
PKCS11
POP3
PRNG
REST
REST Misc
RSA
SCP
SCard
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
ScMinidriver
SharePoint
SharePoint Online
Signing in the Cloud
Socket/SSL/TLS
Spider
Stream
Tar Archive
ULID/UUID
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl
uncategorized

 

 

 

(Visual FoxPro) Modify Parts of JSON Document

Demonstrates how to modify parts of a JSON document. This example uses the following JSON document:

{
   "fruit": [
      	{
         "kind": "apple",
	 "count": 24,
	 "fresh": true,
	 "extraInfo": null,
	 "listA": [ "abc", 1, null, false ],
	 "objectB": { "animal" : "monkey" }
      	},
	{
         "kind": "pear",
	 "count": 18,
	 "fresh": false,
	 "extraInfo": null
	 "listA": [ "xyz", 24, null, true ],
	 "objectB": { "animal" : "lemur" }
	}
    ],
    "list" : [ "banana", 12, true, null, "orange", 12.5, { "ticker": "AAPL" }, [ 1, 2, 3, 4, 5 ] ],
    "alien" : true
}

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

LOCAL loJson
LOCAL lnSuccess
LOCAL loListA
LOCAL lnBNull
LOCAL loTickerObj
LOCAL loAa
LOCAL loAFruit
LOCAL loAppleObj
LOCAL loPearObj

* For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.JsonObject')
loJson = CreateObject('Chilkat.JsonObject')

* Load the JSON from a file.
lnSuccess = loJson.LoadFile("qa_data/json/modifySample.json")
IF (lnSuccess <> 1) THEN
    ? loJson.LastErrorText
    RELEASE loJson
    CANCEL
ENDIF

* This example will not check for errors (i.e. null / false / 0 return values)...

* Get the "list" array:
loListA = loJson.ArrayOf("list")

* Modify values in the list.

* Change banana to plantain
lnSuccess = loListA.SetStringAt(0,"plantain")

* Change 12 to 24
lnSuccess = loListA.SetIntAt(1,24)

* Change true to false
lnSuccess = loListA.SetBoolAt(2,0)

* Is the 3rd item null?
lnBNull = loListA.IsNullAt(3)

* Change "orange" to 32.
lnSuccess = loListA.SetIntAt(4,32)

* Change 12.5 to 31.2
lnSuccess = loListA.SetNumberAt(5,"31.2")

* Replace the { "ticker" : "AAPL" } object with { "ticker" : "GOOG" }
* Do this by deleting, then inserting a new object at the same location.
lnSuccess = loListA.DeleteAt(6)
lnSuccess = loListA.AddObjectAt(6)
loTickerObj = loListA.ObjectAt(6)
lnSuccess = loTickerObj.AddStringAt(-1,"ticker","GOOG")

RELEASE loTickerObj

* Replace "[ 1, 2, 3, 4, 5 ]" with "[ "apple", 22, true, null, 1080.25 ]"
lnSuccess = loListA.DeleteAt(7)
lnSuccess = loListA.AddArrayAt(7)
loAa = loListA.ArrayAt(7)
lnSuccess = loAa.AddStringAt(-1,"apple")
lnSuccess = loAa.AddIntAt(-1,22)
lnSuccess = loAa.AddBoolAt(-1,1)
lnSuccess = loAa.AddNullAt(-1)
lnSuccess = loAa.AddNumberAt(-1,"1080.25")
RELEASE loAa

RELEASE loListA

* Get the "fruit" array
loAFruit = loJson.ArrayAt(0)

* Get the 1st element:
loAppleObj = loAFruit.ObjectAt(0)

* Modify values by member name:
lnSuccess = loAppleObj.SetStringOf("fruit","fuji_apple")
lnSuccess = loAppleObj.SetIntOf("count",46)
lnSuccess = loAppleObj.SetBoolOf("fresh",0)
lnSuccess = loAppleObj.SetStringOf("extraInfo","developed by growers at the Tohoku Research Station in Fujisaki")

RELEASE loAppleObj

* Modify values by index:
loPearObj = loAFruit.ObjectAt(1)
lnSuccess = loPearObj.SetStringAt(0,"bartlett_pear")
lnSuccess = loPearObj.SetIntAt(1,12)
lnSuccess = loPearObj.SetBoolAt(2,0)
lnSuccess = loPearObj.SetStringAt(3,"harvested in late August to early September")
RELEASE loPearObj

RELEASE loAFruit

loJson.EmitCompact = 0
? loJson.Emit()

RELEASE loJson


 

© 2000-2024 Chilkat Software, Inc. All Rights Reserved.