Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Parse and create JSON with Chilkat ActiveX
#1
Setup

Download the 32-bit zip file from https://www.chilkatsoft.com/downloads_ActiveX.asp
Unzip the dll to the QM folder. Don't need other files.

Run this macro if need a manifest file for registration-free COM activation using __ComActivator.
Macro Chilkat create manifest
 
Code:
Copy      Help
;Creates manifest file for __ComActivator ca.Activate("$qm$\ChilkatAx-win32.X.manifest")

__ComActivator_CreateManifest "$qm$\ChilkatAx-win32.dll"

Examples

Macro Parse JSON
 
Code:
Copy      Help
;Uses Chilkat ActiveX.
;Docs: https://www.chilkatsoft.com/refdoc/xChilkatJsonObjectRef.html
;Download: https://www.chilkatsoft.com/downloads_ActiveX.asp
;JSONPath online evaluator and docs: https://jsonpath.com/

;__ComActivator ca.Activate("$qm$\ChilkatAx-win32.X.manifest") ;;enable this if want to use the library without COM registration, eg in exe. Note: QM anyway auto-registers when compiling.
typelib Chilkat "$qm$\ChilkatAx-win32.dll"

out

str json=
;{
;"one":"ONE",
;"two":2,
;"obj": {
;;"three":"THREE",
;;"four":"FOUR",
;;"bool":true
;},
;"arr":["A", "B", {"six":"SIX","seven":"SEVEN"}]
;}

ChilkatJsonObject j._create
j.Load(json)

out j.StringAt(0)
out j.IntAt(1)
out j.IntOf("two")
out j.StringOf(".obj.four")
out j.BoolOf(".obj.bool")
out j.FindObjectWithMember("three").StringOf("four")
out j.FindObjectWithMember("six").StringOf("seven")

;arrays:
out j.ArrayOf("arr").StringAt(1) ;;OK
;out j.StringOf(".arr[1]") ;;why fails?
out j.StringOf(".arr[1:2]") ;;OK
out j.StringOf(".arr[2:3].six") ;;OK
out j.ArrayOf("arr").ObjectAt(2).StringOf("seven") ;;OK

;if need a variable:
;IChilkatJsonArray a=j.ArrayOf("arr"); out a.StringAt(1)
;IChilkatJsonObject o=j.ArrayOf("arr").ObjectAt(2); out o.StringOf("six")

;the functions don't throw exceptions but set last error:
if(!j.LastMethodSuccess) out j.LastErrorText

Macro Create JSON
Code:
Copy      Help
;Uses Chilkat ActiveX.
;Docs: https://www.chilkatsoft.com/refdoc/xChilkatJsonObjectRef.html
;Download: https://www.chilkatsoft.com/downloads_ActiveX.asp

;__ComActivator ca.Activate("$qm$\ChilkatAx-win32.X.manifest") ;;enable this if want to use the library without COM registration, eg in exe. Note: QM anyway auto-registers when compiling.
typelib Chilkat "$qm$\ChilkatAx-win32.dll"

out

ChilkatJsonObject j._create
j.AppendString("one" "ONE")
j.AppendInt("two" 2)
IChilkatJsonObject o=j.AppendObject("obj")
o.AppendString("three" "THREE")
o.AppendBool("four" 1)
IChilkatJsonArray a=j.AppendArray("arr")
a.AddStringAt(-1 "A")
a.AddStringAt(-1 "B")
a.AddObjectAt(-1)
a.ObjectAt(a.size-1).AppendString("C" "CC")
a.ObjectAt(a.size-1).AppendBool("D" 1)

j.EmitCompact=0
str json=j.Emit()
out json


Messages In This Thread
Parse and create JSON with Chilkat ActiveX - by Gintaras - 06-10-2025, 07:29 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)