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

PowerBuilder 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

 

 

 

(PowerBuilder) 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

integer li_rc
oleobject loo_Json
integer li_Success
oleobject loo_ListA
integer li_BNull
oleobject loo_TickerObj
oleobject loo_Aa
oleobject loo_AFruit
oleobject loo_AppleObj
oleobject loo_PearObj

loo_Json = create oleobject
// Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
li_rc = loo_Json.ConnectToNewObject("Chilkat.JsonObject")
if li_rc < 0 then
    destroy loo_Json
    MessageBox("Error","Connecting to COM object failed")
    return
end if

// Load the JSON from a file.
li_Success = loo_Json.LoadFile("qa_data/json/modifySample.json")
if li_Success <> 1 then
    Write-Debug loo_Json.LastErrorText
    destroy loo_Json
    return
end if

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

// Get the "list" array:
loo_ListA = loo_Json.ArrayOf("list")

// Modify values in the list.

// Change banana to plantain
li_Success = loo_ListA.SetStringAt(0,"plantain")

// Change 12 to 24
li_Success = loo_ListA.SetIntAt(1,24)

// Change true to false
li_Success = loo_ListA.SetBoolAt(2,0)

// Is the 3rd item null?
li_BNull = loo_ListA.IsNullAt(3)

// Change "orange" to 32.
li_Success = loo_ListA.SetIntAt(4,32)

// Change 12.5 to 31.2
li_Success = loo_ListA.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.
li_Success = loo_ListA.DeleteAt(6)
li_Success = loo_ListA.AddObjectAt(6)
loo_TickerObj = loo_ListA.ObjectAt(6)
li_Success = loo_TickerObj.AddStringAt(-1,"ticker","GOOG")

destroy loo_TickerObj

// Replace "[ 1, 2, 3, 4, 5 ]" with "[ "apple", 22, true, null, 1080.25 ]"
li_Success = loo_ListA.DeleteAt(7)
li_Success = loo_ListA.AddArrayAt(7)
loo_Aa = loo_ListA.ArrayAt(7)
li_Success = loo_Aa.AddStringAt(-1,"apple")
li_Success = loo_Aa.AddIntAt(-1,22)
li_Success = loo_Aa.AddBoolAt(-1,1)
li_Success = loo_Aa.AddNullAt(-1)
li_Success = loo_Aa.AddNumberAt(-1,"1080.25")
destroy loo_Aa

destroy loo_ListA

// Get the "fruit" array
loo_AFruit = loo_Json.ArrayAt(0)

// Get the 1st element:
loo_AppleObj = loo_AFruit.ObjectAt(0)

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

destroy loo_AppleObj

// Modify values by index:
loo_PearObj = loo_AFruit.ObjectAt(1)
li_Success = loo_PearObj.SetStringAt(0,"bartlett_pear")
li_Success = loo_PearObj.SetIntAt(1,12)
li_Success = loo_PearObj.SetBoolAt(2,0)
li_Success = loo_PearObj.SetStringAt(3,"harvested in late August to early September")
destroy loo_PearObj

destroy loo_AFruit

loo_Json.EmitCompact = 0
Write-Debug loo_Json.Emit()


destroy loo_Json

 

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