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

Tcl 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

 

 

 

(Tcl) JSON: Miscellaneous Operations

Demonstrates a variety of JSON API methods. This example uses the following JSON document:

{
   "alphabet": "abcdefghijklmnopqrstuvwxyz",
   "sampleData" : {
           "pi": 3.14,
	   "apple": "juicy",
	   "hungry": true,
	   "withoutValue": null,
           "answer": 42
          
	}
}

Chilkat Tcl Extension Downloads

Chilkat Tcl Extension Downloads

load ./chilkat.dll

set json [new_CkJsonObject]

CkJsonObject_put_EmitCompact $json 0

# Assume the file contains the data as shown above..
set success [CkJsonObject_LoadFile $json "qa_data/json/sample2.json"]
if {$success != 1} then {
    puts [CkJsonObject_lastErrorText $json]
    delete_CkJsonObject $json
    exit
}

# First navigate to the "sampleData" object:
# sampleData is a CkJsonObject
set sampleData [CkJsonObject_ObjectOf $json "sampleData"]

# Demonstrate BoolAt and BoolOf
puts "hungry: [CkJsonObject_BoolOf $sampleData hungry]"
puts "hungry: [CkJsonObject_BoolAt $sampleData 2]"

# StringOf returns the value as a string regardless of it's actual type:
puts "pi: [CkJsonObject_stringOf $sampleData pi]"
puts "answer: [CkJsonObject_stringOf $sampleData answer]"
puts "withoutValue: [CkJsonObject_stringOf $sampleData withoutValue]"
puts "hungry: [CkJsonObject_stringOf $sampleData hungry]"

# Demonstrate IsNullOf / IsNullAt
puts "withoutValue is null? [CkJsonObject_IsNullOf $sampleData withoutValue]"
puts "withoutValue is null? [CkJsonObject_IsNullAt $sampleData 3]"
puts "apple is null? [CkJsonObject_IsNullOf $sampleData apple]"
puts "apple is null? [CkJsonObject_IsNullAt $sampleData 1]"

# IntOf
puts "answer: [CkJsonObject_IntOf $sampleData answer]"

# SetNullAt, SetNullOf
# Set "pi" to null
set success [CkJsonObject_SetNullAt $sampleData 0]
# Set "answer" to null
set success [CkJsonObject_SetNullOf $sampleData "answer"]

# Show the changes:
puts [CkJsonObject_emit $json]

# Restore pi and apple:
set success [CkJsonObject_SetNumberAt $sampleData 0 "3.14"]
set success [CkJsonObject_SetNumberOf $sampleData "answer" "42"]

# Show the changes:
puts [CkJsonObject_emit $json]

# Add a null value named "afterApple" just after "apple"
set success [CkJsonObject_AddNullAt $sampleData 2 "afterApple"]

# Add a boolean value just after "pi"
set success [CkJsonObject_AddBoolAt $sampleData 1 "afterPi" 0]

delete_CkJsonObject $sampleData

# Examine the changes..
puts [CkJsonObject_emit $json]

delete_CkJsonObject $json

 

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