Chilkat Examples

ChilkatHOMEAndroid™Classic ASPCC++C#Mono C#.NET Core C#C# UWP/WinRTDataFlexDelphi ActiveXDelphi DLLVisual FoxProJavaLianjaMFCObjective-CPerlPHP ActiveXPHP ExtensionPowerBuilderPowerShellPureBasicPythonRubySQL ServerSwiftTclUnicode CUnicode C++Visual Basic 6.0VB.NETVB.NET UWP/WinRTVBScriptXojo PluginNode.jsExcel

Node.js Examples


ASN.1
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Service Bus
Bounced Email
Box
CSR
CSV
Certificates
Compression
DKIM / DomainKey
DSA
Diffie-Hellman
Digital Signatures
Dropbox
ECC
Email Object
Encryption
FTP
Facebook
Firebase
GeoOp
Google APIs
Google Calendar
Google Cloud Storage
Google Drive
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
Microsoft Graph
NTLM
OAuth1
OAuth2
OneDrive
OpenSSL
Outlook
PEM
PFX/P12
POP3
PRNG
PayPal
Peoplevox
QuickBooks
REST
RSA Encryption
SCP
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
SharePoint
Shopify
Socket/SSL/TLS
Spider
Stream
Stripe
SugarCRM
Tar Archive
Twitter
VoiceBase
Walmart
WebSocket
XML
XML Digital Signatures
XMP
Xero
Zip
curl
eBay

 

 

 

(Node.js) JSON Escape and Unescape a String

The encoding mode keyword "json" was added in Chilkat v9.5.0.66 to provide the ability to escape and unescape JSON strings. See Chilkat Encodings for the full list of encoding keywords, such as "base64", "hex", "url", etc.

Install Chilkat for Node.js using npm at

Chilkat npm packages for Node.js and Electron
on Windows, Linux, MacOSX, and ARM

Supports Node.js 4.*, 5.*, 6.*, 7.*, 8.*, and Electron 1.6.* and 1.7.*

var os = require('os');
if (os.platform() == 'win32') {  
    var chilkat = require('chilkat_node6_win32'); 
} else if (os.platform() == 'linux') {
    if (os.arch() == 'arm') {
        var chilkat = require('chilkat_node6_arm');
    } else if (os.arch() == 'x86') {
        var chilkat = require('chilkat_node6_linux32');
    } else {
        var chilkat = require('chilkat_node6_linux64');
    }
} else if (os.platform() == 'darwin') {
    var chilkat = require('chilkat_node6_macosx');
}

function chilkatExample() {

    //  Note: This example requires Chilkat version 9.5.0.66 or greater.

    var sb = new chilkat.StringBuilder();

    sb.Append("backslash: \\\\, A: \\u0041");
    console.log(sb.GetAsString());

    //  The output is:
    //     backslash: \\, A: \u0041

    //  Starting in Chilkat v9.5.0.66, the keyword "json" can be used
    //  to escape and unescape.  To escape is to encode.  To unescape is to decode.

    //  Unescape (decode) the string in sb.
    sb.Decode("json","utf-8");
    console.log(sb.GetAsString());

    //  After JSON unescaping:
    //     backslash: \, A: A

    //  Now JSON escape the string.
    sb.Encode("json","utf-8");
    console.log(sb.GetAsString());

    //  After JSON escaping:
    //     backslash: \\, A: A

    //  Note: The "A" is not escaped to "\u0041" because there is no need.
    //  The "\uXXXX" format would be produced for non-printable control chars.

}

chilkatExample();

 

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