JSON Parser for AngelScript

As you may know, Angelscript is the scripting engine used by KUIML, our user interface description language for all our plug-ins, and can also be used to write DSP processing with Plug’n Script.

Many developers using Plug’n Script have been asking for a JSON parser and writer to use with Plug’n Script, as a complement to the built-in XML parser. Here is one that I found some time ago, written in Angelscript, that you may want to use to parse and write JSON in your own plug-in. It has a friendly MPL license, so check it out!

A JSON parser for AngelScript (github.com)

Here is an example of how you can use the parser (adapted from the Github Wiki):

  #include "Jsona/Jsona"

  string test = "{\"date\":\"20191223\",\"articles\":[{\"id\":12,\"title\":\"We're out of beta!\",\"category\":0},{\"id\":13,\"title\":\"The cake is a lie!\",\"category\":1}]}";
  
  // parse JSON string
  Jsona::Value@ val = Jsona::parse(test);
  
  // get data straight out of Value
  dictionary@ root = dictionary(val);
  
  // add new key to object, with bi-directional data flow (by making use of reference).
  root["homepage"] = Jsona::Value("https://github.com/Paranoid-AF");
  root["age"] = Jsona::Value(19);
  
  // directly manipulate Value
  Jsona::Value@ valInner = val["date"];
  if(valInner.type() == Jsona::STRING_VALUE){
    valInner.set(string(valInner) + " but whatever.");
  }
  
  // directly manipulate Value, with bi-directional data flow (by making use of reference).
  array<Jsona::Value@>@ arr = array<Jsona::Value@>(val["articles"]);
  arr.insertLast(Jsona::Value("Hola!"));
  arr[2].set("Hello");
  
  // operator overloads, always use string for index, even if it's an array.
  val["articles"]["0"]["title"] = Jsona::Value("Actually, no.");

Try it out, and tell us if it works for you!

Leave a Reply

Your email address will not be published. Required fields are marked *