What is the best JSON parser/stringify library to use with AHK 2? I'm so confused. Topic is solved

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
IMTheNachoMan
Posts: 59
Joined: 01 Mar 2022, 17:07
Contact:

What is the best JSON parser/stringify library to use with AHK 2? I'm so confused.

19 Sep 2023, 19:27

I just need a simple/basic JSON parser to parse simple data like below. I'm searching the forums but getting lost because there are so many versions, and different names/authors being thrown around.

Can someone please just help me with the best, most light weight, and fastest JSON library to use?

Code: Select all

{
    "layouts": [
        {
            "name": "Two Vertical Split",
            "windows": [
                {
                    "topLeftRowNumber"   : 0,
                    "topLeftColumnNumber": 0,
                    "numberOfRows"       : 12,
                    "numberOfColumns"    : 6
                },
                {
                    "topLeftRowNumber"   : 0,
                    "topLeftColumnNumber": 6,
                    "numberOfRows"       : 12,
                    "numberOfColumns"    : 6
                }
            ]
        },
        {
            "name": "4 Splits",
            "windows": [
                {
                    "topLeftRowNumber"   : 0,
                    "topLeftColumnNumber": 0,
                    "numberOfRows"       : 6,
                    "numberOfColumns"    : 6
                },
                {
                    "topLeftRowNumber"   : 0,
                    "topLeftColumnNumber": 6,
                    "numberOfRows"       : 6,
                    "numberOfColumns"    : 6
                },
                {
                    "topLeftRowNumber"   : 6,
                    "topLeftColumnNumber": 0,
                    "numberOfRows"       : 6,
                    "numberOfColumns"    : 6
                },
                {
                    "topLeftRowNumber"   : 6,
                    "topLeftColumnNumber": 6,
                    "numberOfRows"       : 6,
                    "numberOfColumns"    : 6
                }
            ]
        },
        {
            "name": "FullScreen",
            "windows": [
                {
                    "topLeftRowNumber"   : 0,
                    "topLeftColumnNumber": 0,
                    "numberOfRows"       : 12,
                    "numberOfColumns"    : 12
                }
            ]
        }
    ]
}
XMCQCX
Posts: 250
Joined: 14 Oct 2020, 23:44

Re: What is the best JSON parser/stringify library to use with AHK 2? I'm so confused.

19 Sep 2023, 19:57

Recently, I was searching for a v2 JSON library as well. Ultimately, I decided to use the one below. Although I can't confirm it's the best option, it gets the job done. I haven't conducted a speed test comparison. You can download it here:
https://github.com/TheArkive/JXON_ahk2.
bonobo
Posts: 76
Joined: 03 Sep 2023, 20:13

Re: What is the best JSON parser/stringify library to use with AHK 2? I'm so confused.

19 Sep 2023, 20:24

Do you need the parsing logic to be written entirely in AHK? If so, go with either of the above suggestions.

If not, and esp. if you frequently need to handle very large JSON files, I'd use either cpp-json:
viewtopic.php?f=83&t=100602
or LightJSON:
viewtopic.php?p=539759#p539759

I'd also watch this thread for when cJson gets converted to v2:
viewtopic.php?style=19&f=6&t=92320
IMTheNachoMan
Posts: 59
Joined: 01 Mar 2022, 17:07
Contact:

Re: What is the best JSON parser/stringify library to use with AHK 2? I'm so confused.

19 Sep 2023, 20:37

mikeyww wrote:
19 Sep 2023, 19:46
Here is one. https://github.com/cocobelgica/AutoHotkey-JSON
Thank you. I've seen that one mentioned a few times.
XMCQCX wrote: Recently, I was searching for a v2 JSON library as well. Ultimately, I decided to use the one below. Although I can't confirm it's the best option, it gets the job done. I haven't conducted a speed test comparison. You can download it here:
https://github.com/TheArkive/JXON_ahk2.
This one seems to be a newer/updated version of the other one. I will give this one a try. Thanks.
bonobo wrote: Do you need the parsing logic to be written entirely in AHK?
I do not know what that means. I'm not dealing with large JSON files but will the two you recommended give me better performance? And will my AHK script work on any/every Windows 10 machine that has AHK 2 installed?

Based on what you said, I infer:
Is that right?
bonobo
Posts: 76
Joined: 03 Sep 2023, 20:13

Re: What is the best JSON parser/stringify library to use with AHK 2? I'm so confused.

19 Sep 2023, 21:00

but will the two you recommended give me better performance?
Last time I tested this (in v1), either LightJSON or especially cJSON is at least one order of magnitude (>10 times) faster. In v2 I use cpp-json and am perfectly content with it. That said, if you don't need to parse large JSON files (or if you don't need to frequently parse small JSON files for very time-sensitive applications) the above suggested options are imo perfectly adequate, and you can easily modify them as they are written in AHK. cJSON or cpp-json are harder to modify as they are both written in a much lower-level language, but both are still open source, so it's still possible. I don't know about ranking the different options; which is best depends on the use case.
geek
Posts: 1053
Joined: 02 Oct 2013, 22:13
Location: GeekDude
Contact:

Re: What is the best JSON parser/stringify library to use with AHK 2? I'm so confused.

20 Sep 2023, 08:14

cJson for v2 is getting very close to release, giving C level performance without the need for DLLs. See here https://p.ahkscript.org/?p=0bce480c for a beta copy. I've been tracking its development on my ko-fi blog here https://ko-fi.com/g33kd
jsong55
Posts: 255
Joined: 30 Mar 2021, 22:02

Re: What is the best JSON parser/stringify library to use with AHK 2? I'm so confused.

22 Sep 2023, 00:21

neogna2 wrote:
20 Sep 2023, 03:10
There is also
https://github.com/thqby/ahk2_lib/blob/master/JSON.ahk
which is pure AHK (no .dll dependencies, unlike cpp-json also by thqby)
I personally use this.
IMTheNachoMan
Posts: 59
Joined: 01 Mar 2022, 17:07
Contact:

Re: What is the best JSON parser/stringify library to use with AHK 2? I'm so confused.

22 Sep 2023, 08:18

In my super basic performance test, https://github.com/thqby/ahk2_lib/blob/master/JSON.ahk did seem to perform better than the other two. But I'm new to AHK so I don't know if I did it right.

Not that it matters for me. I just need to read 1 small JSON file when the script starts because it has configuration data.

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: niCode and 32 guests