Recommended Posts

This UDF brings the power and flexibility of jq to AutoIt scripts. jq is an open-source, powerful, and flexible command-line based JSON processor. As it says on their website, jq is like 'sed' for JSON. jq can be used for the simplest of tasks like retrieving JSON objects and values, to very advanced JSON processing using its numerous built-in functions and conditional processing. Its built-in functions can handle math, selection, conditional processing, mapping, object and array manipulation, flattening, reduction, grouping, and much more. You can even create your own jq functions. You can learn more about jq and even play with it in real-time, using jq's online jq playground, all on their website.

Here and some helpful links to get you more familiar with jq, what can be done with it, its built-in functions, and its syntax.

jq is a single 32 or 64 bit executable that has no other dependencies. Just like using the SQLite UDF, the only requirement to use this UDF is that the jq executable reside in a location in which the UDF can execute it. The latest win32 & win64 versions have been included in the UDF download. You can always get newer versions from the jq website.

I don't consider this a replacement for some of the other JSON UDFs like the one based on JSMN. If speed and simple JSON parsing are you primary goals, then other UDFs may be a better choice. However, if you like having the power to do just about anything related to JSON processing/manipulation, using a single UDF, then jq may be worth checking out. It can be used by novices and experts alike. Below, is a brief explanation of how jq works, how to use the jq UDF, and a few examples of how to do some simple tasks. If you want to learn more about jq and what it can do, I would highly suggest checking out the jq website and some of the other resources listed above.

jq at a high level

Like 'sed', jq reads JSON in, either through STDIN or one or more files, processes it thru one or more "filters", and outputs the results. You can, optionally, supply "options" that affect how it reads the input, where it gets its "filters", and how it writes its output. It looks a little like this:

So in jq lingo, you basically use "Filters" to tell jq what you want it to do. So in the UDF file, that is why the main functions ( _jqExec() and _jqExecFile() ) refer to filters and options. Please make note that jq works with relatively strict JSON. This means that all JSON read must be conform to the standard. Luckily, jq is pretty good at identifying where a format error exists in non standard JSON.

The jq UDF

There are 2 main funtions in the UDF file, _jqExec and jqExecFile. With these 2 functions, you can pretty much do anything that jq can do. The only difference between to two functions is whether the JSON is supplied by a string or a file. The 2 primary functions simply call the jq executable with the supplied information, after properly formatting the parameters. There are additional functions in the UDF to easily pretty-print your json, compact-print your json, dump the json data with its associated paths, and see if specific JSON keys exist, but they all just execute the _jqExec or _jqExecFile function with the proper filter. There are also a couple of extra functions to display what version of the UDF and jq executable you are currently using. There are also a couple of functions to enable and disable logging of jq information for debugging purposes. Most of the jq UDF file functions return an @error if unsuccessful. Some also include @extended info. Please see the actual function headers for more information on their usage and return values.

The 2 primary functions below just format your jq request and pass it on the jq executable. The functions will also properly escape double quotes (") that are used in the filter. For most simple tasks, you just need to supply the JSON source and a filter.

As stated earlier, the jq executable must reside somewhere where the script can locate and execute it. The _jqInit() function always has to be executed before any jq processing occurs. _jqInit() merely locates the executable or uses the supplied path. It also clears any previous debug log. The jq UDF folder contains a jq example script that has several examples to how to do some of the most common JSON processing tasks. Here are a few examples to get you started:

The examples above, and the ones in the example file, merely scratch the surface of what jq can do. It may look intimidating at first but it really isn't that bad once you start playing with it.

If you have any suggestions on how to make the UDF better, or find a bug, please let me know. I only started using it about a week ago. Nevertheless, if you have any questions regarding the UDF, or how to perform a certain task using jq, I'll try my best to answer them. Since jq has been around for a while now, there's also several jq-related questions and answers on StackOverflow.

Hi AutoIters!
Here is my new UDF about GUIs: it's an enhanced mixture of Advanced InputBox (deprecated) and KODA Parser (deprecated), with additional functions.
What you can do with it:
Parse KODA files and directly create GUIs (_GUIUtils_CreateFromKODA)
Parse a simple JSON form definition to simply create advanced InputBoxes with any amount/type of input controls (_GUIUtils_CreateFromJSON)
Created GUIs are returned as Scripting.Dictionary objects, and you have helper functions to access GUIs controls by their names (_GUIUtils_HWnd, _GUIUtils_CtrlID, _GUIUtils_HCtrl ...)
A function that can make a GUI created from KODA/JSON (defined by it's $oForm object) and make it a modal InputDialogBox (just like InputBox, but returns all entered data as Scripting.Dictionary object)
Functions are documented, and there are some examples.
Consider this UDF as beta, but since I'm currently using it in a small commercial project, it should become production ready in near future.
To always get the latest code version, get it from Github (more up to date than this topic).
Update 04/02/2020:
New simple application example
Fixed focused control handling in _GUIUtils_InputDialog
Reset input values before returning from _GUIUtils_InputDialog
Fixed CloseOnEsc in _GUIUtils_InputDialog
Fixed Input not reset
Fixed all ListBox items are selected
Project now on GitHub https://github.com/matwachich/autoit-guiutils/
Update 05/02/2020:
Support for nodate for Date and Time input controls (pass null value)
New handling of focused control _GUIUtils_InputDialog: Now, you can specify the focused control in $oInitialData by setting "controlName:focus" = True
Updated documentation of _GUIUtils_InputDialog
Update 07/02/2020:
Bug corrected when setting Data input control
Added: abillity to read a single input control
New functions (_GUIUtils_GetInputs, _GUIUtils_WriteInputs), documentation completion.
Readme file and screenshots on Github Page
GUIUtils.zip

How can I go about transmitting data in text format utf8?
Thanks in advance for the help.
In the zip file:
- CurlJsonPost.au3: this script
- Curl.au3: UDF by Ward (thank you!)
- data.json: json srting for command line test

Note: using Curl.exe with json string saved in a file (utf8 encoded) named data.json, works perfectly
To try with the command line tool:
- save data.json in curl\bin directory
- open cmd.exe and cd to curl\bin directory
- Enter the following command:
curl -H "Content-Type: application/json" --data @data.json https://httpbin.org/post

Hi all, I wasnt active in this Forum forum for Years. 😅
Since I need something with Json in AutoIt i write a little UDF to save a variable to file to read it with another language - and back. After a while until my other script grows i thought - lets integrate all variables wich is possible, because i want have arrays to.
This is my first public UDF in Autoit - normaly my AutoIt scripts are quick an dirty.... - like the examples for this udf. - someone want to write nice examples?
I tried to write this UDF properly, cared for processing speed, low mem consumption as possible, a short code, and a high usability without beeing very familiar with arrays.
What is it for? - convert nearly all types of variables to a json string for saving it in a file or to an ini. Read it back in to a same formated variable and preserv variable types. All array types are supported with nested arrays, the only restriction is ram and array/stringsize - and time if the array is very big. You can use Filters for variable types and some other options.
If anyone found a bug or any suggestions, please post it.

Example : https://api.imgur.com/3/account/me/images
The string received is like :
{"data":[{"id":"fd6f54s","title":null,"description":null,"datetime":1574502473,"type":"image\/png","animated":false,"width":1147,"height":715,"size":53516,"views":18,"bandwidth":963288,"vote":null,"favorite":false,"nsfw":null,"section":null,"account_url":"ACCOUNT","account_id":ACCOUNTID,"is_ad":false,"in_most_viral":false,"has_sound":false,"tags":[],"ad_type":0,"ad_url":"","edited":"0","in_gallery":false,"deletehash":"d6f5sd4fsf","name":"image","link":"https:\/\/i.imgur.com\/fd6f54s.png"}
I'm using JSON.au3 UDF and i don't manage to make it working :
Local $Obj = Json_Decode($hRequestSSL)
Local $Links = Json_Get($Obj, '["data"]["link"]')
The Json_Decode sends in console :
"E:\Portable\Dev\AutoIt3\IncludeP\JSON.au3" (374) : ==> Variable must be of type "Object".:
Return $Object.Keys()
Return $Object^ ERROR
It says it's not an object or i have seen in some UDF that Json_Decode takes a string as parameter.
I don't know what's wrong.