Parsing JSON in Ubot Studio 

 November 2, 2022

By  Reed

Working with JSON in ubot studio and parsing it is relatively easy once you know what to do. However, there are some things you should be aware of as there are some issues.

Things to know:

  • Running a lot of javascript in Ubot 6 seems to break it and be problematic.
  • Running the jsonpath parser plugin within a “Section” can cause ubot to crash in ubot 6.
  • You should be able to just return a result in javascript when using $eval, but cannot.
  • The $eval function will update automatically every time you run a different $eval function so there’s no need to continue running the $eval function with the variable.
  • You seemingly can’t return the variable in the first $eval function and must have a second $eval return the variable itself.

How to Parse JSON in Ubot Studio

There are 2 ways we will cover that will allow you to parse JSON and store as a variable for the rest of your bot to work with. These solutions are:

  • JSONPath Plugin by Aymen of Ubot-Plugins.com (link below)
  • Running Javascript in the $eval function that comes with Ubot.

Both solutions are free and will return the values of JSON array for you to work with. This is especially helpful if you are working with JSON database tools like CouchDB or retrieving data from an API.

comment("Using JSONPath Plugin")

set(#Get,$plugin function("HeopasCustom.dll", "$Heopas HTTP Get", "http://elitebotters.com/wp-json/wp/v2/posts/13040", "", "", "", "", 3000),"Global")
set(#Json,$plugin function("JSONpath.dll", "$JSONpath parser", #Get, "$.id"),"Global")

divider

comment("Using Javascript $eval function")

set(#eval,$eval("const json = \'\{\"result\":true, \"count\":42\}\';
const obj = JSON.parse(json);

x = obj.count;
// expected output: 42
"),"Global")
set(#eval,$eval("x"),"Global")

Resources:

JsonPath Parser Plugin – Ubot Plugins (ubot-plugins.com)


Reed


Warning: Invalid argument supplied for foreach() in /home/actionreed/public_html/su/wp-content/themes/thrive-theme/inc/classes/class-thrive-theme-comments.php on line 463

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

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}

Subscribe to our newsletter now!

RSS
Follow by Email
YouTube
X

Forgot Password?

Join Us