Need help with JSON serialization in the VBScript

I would like to ask if anyone could show me how deserialize JSON file into an object using VBScript. I want to use it in a script in DOpus.

And here's the serializable class representing JSON file structure. Just in case you need it.

public class AlternateTitle	
	public string title { get; set; }
	public int Number { get; set; }

public class Image
	public string Type { get; set; }
	public string url { get; set; }

public class Statistics
	public int FileCount { get; set; }
	public object sizeOnDisk { get; set; }
	public DateTime? NextDate { get; set; }

public class Ratings
	public int votes { get; set; }
	public double value { get; set; }

public class Example
	public string title { get; set; }
	public IList<AlternateTitle> alternateTitles { get; set; }
	public string sortTitle { get; set; }
	public object sizeOnDisk { get; set; }
	public string status { get; set; }
	public string overview { get; set; }
	public IList<Image> images { get; set; }
	public int year { get; set; }
	public string path { get; set; }
	public int profileId { get; set; }
	public DateTime firstSeen { get; set; }
	public DateTime lastSync { get; set; }
	public IList<string> genres { get; set; }
	public IList<int> tags { get; set; }
	public DateTime added { get; set; }
	public Ratings ratings { get; set; }
	public int id { get; set; }

Thanks in advance for any help.

In JScript we can use the JSON.Parse method JSON..

If you can figure out VBscript you can prob figure out JScript. I might be easier to mover over for this task.

Otherwise this might help you.

Is it possible to import and use dlls in the scripts? That would solve all my problems - I would write the most stuff in c# as a library and simply use it in the rudimentary vbscript inside dopus...

Not that I know of. :frowning:
I would rather write c# as well. I use JScript.

If you package it as a COM object you'd be able to access it from VBScript. But switching to JScript would probably be easier.

@Jon sorry for bothering, but could you please elaborate?

I am not a professional programmer. It is simply my hobby. And actually the only thing I know is c#. I have tried some other languages years ago - python, lua, just a tiny bit of javascript - did not like those, especially javascript. But when I tried c# - I loved it. It just made sense to me.

I actually just started learning javascript a couple of days ago - watching video courses on pluralsight. Sadly it still does not make sense to me yet. No classes, no structure and omg - the callback hell :slight_smile:

Anyway, could you please elaborate, why jscript is better/easier than vbscript? Or point me to the right direction, where I could read up on it?
Actually, did you mean switching to jscript would be easier for this particular situation, or in general?
Not that I like vbscript - not at all. I assume jscript is better even because it's very simmilar to javascript? So learning one, helps learning another...

And an additional question about scripting in dopus.
I have a couple of Path Folder Formats saved. In these folder formats I use custom columns, which I populate using a vbscript. The script reads the information from the description.ini file which is located in these source folders. That file basically holds some information on the subfolders located in those source folders.
The problem I'm having, that with a large amount of subfolders it takes quite a long time for the columns to get populated with the data. I assume the description.ini file gets parsed again and again on every subfolder and every column.
I was wondering, is there a way to have some global variable in dopus scripting, which I could use to hold the data for all these subfolders, so to avoid the redundant ini file parsing... Instead, the vbscript would simply get the info from this global object, which should be extremely fast?
I hope I'm making myself clear.

Also, is there any way to have a usable hyperlink in a custom column?

JScript is not better than VBscript, Both get the job done.

You want to read JSON (Java Script Object Notation), JScript has native support for that (link above) VBscript does not. So if you want to read JSON JScript is better than VBscript.

@Jon is right you can call .net from JScript and VBscript. I have the 'pleasure' using COM at work. I would not use COM. But if you want to give that a go, googling call .net dll from vbscript link 1 link 2. looks like a good start.

I have a few DOpus scripts that parse and write JSON, and put stuff in global vars. They are all JScript. They might help you get going. Let me know what specifics you need.

No, not that I have seen. You Might be able to write a script that would capture the click event and then open the link. Prob would be easier to have a button that when clicked would get the link the same way the column would then open the link.

@wowbagger I would appreciate some example scripts very much. The easiest way to learn, is by example, right? :slight_smile:


  • a jscript example how to deserialize json into an object.
  • a jscript example on how create and use a global object, that could hold global data. Which then could be used by any script - that would be perfect.
  • an example of making custom columns in jscript would be nice. Although I maybe be able to figure out how to reproduce it in jscript from vbscript that I'm using now.

Yep, I was thinking of doing exactly that.

No problem mate. I have been working on a couple of scripts that do this. They create Xpath and Regexp custom columns. The Config is a JSON object that I store in a global variables.

This Regexp is fully functional and does all those things. Regexp Columns
This xpath script is a work in progress. XPath columns

The bit you care about is this.

var doVars = DOpus.vars;
var xmlKey = "XmlCustomColumnsConfig";

function SaveCustomColumns(customColumns){
	var newList = new Array();
	for(var i = 0; i < customColumns.columns.length; ++i) {
		if(customColumns.columns[i]) {
	customColumns.columns = newList;
        var config = JSON.stringify(customColumns, undefined, 2).replace(/(\n)+/g,"\r\n");
        doVars(xmlKey) = config;
        doVars(xmlKey).persist = true;

function LoadCustomColumns(){
        var config = doVars.Exists(xmlKey) ? JSON.parse(doVars.Get(xmlKey)) : null;

  		config = defaultCustomColumns;
	return config

This script will help to see what is in the global variables.

1 Like

@wowbagger thanks alot for these examples. Will try to figure them out :slight_smile:

1 Like