0

How to create JSON object in .vbs file?

I have tried this:

set json = CreateObject("Scripting.Dictionary")

But this object is not supporting json.AddStringAt property. How to create JSON object that supports the json.AddStringAt?

My sample file is

Dim fso, outFile
Set fso = CreateObject("Scripting.FileSystemObject")
Set outFile = fso.CreateTextFile("output.json", True)

set json = CreateObject("Scripting.Dictionary")

index = -1

success = json.AddStringAt(-1,"Title","Pan's Labyrinth")
success = json.AddStringAt(-1,"Director","Guillermo del Toro")
success = json.AddStringAt(-1,"Original_Title","El laberinto del fauno")
success = json.AddIntAt(-1,"Year_Released",2006)

json.EmitCompact = 0
outFile.WriteLine(json.Emit())

outFile.Close
1
  • 3
    If you take a code sample that uses a particular COM object you can't just replace that object with an arbitrary other COM object. Commented Jan 4, 2017 at 10:36

2 Answers 2

2

It looks like there is a library that has the method that you are looking for.

set json = CreateObject("Chilkat_9_5_0.JsonObject")

https://www.chilkatsoft.com/refdoc/xChilkatJsonObjectRef.html

Sign up to request clarification or add additional context in comments.

4 Comments

I have tried this but got this error. ActiveX component can't create object: 'Chilkat_9_5_0.JsonObject'
Did you download and install their ActiveX library?
example-code.com/vbscript/create_json.asp Right above nearly the same example that you posted is the download link.
Installed ActiveX library and now it is working fine.
0

For 32 bit

set json = CreateObject("Chilkat_9_5_0.JsonObject")

For 64bit

set json = CreateObject64("Chilkat_9_5_0.JsonObject")

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.