Sorry how description "Object() is more technically correct than {} but both will work." connected with the code a := Map(), b := Map(), c := Map(), d := Map(), e := Map(), f := Map()?a := Map(), b := Map(), c := Map(), d := Map(), e := Map(), f := Map() ; Object() is more technically correct than {} but both will work.
JSON Serializer - 2022/09/07 - beta.8
Re: JSON - load and dump arrays to/from JSON - AHK v1/2 - 2020/10/10 - a122
Re: JSON - load and dump arrays to/from JSON - AHK v1/2 - 2020/10/10 - a122
Object() is for AHK v1 (just a mistake in the comments). Map() is for AHK v2. Map() and Object() in this context are almost the same, but for different versions of AHK.
« AHK Portable Installer » | « CallTipsForAll » | « TheArkive AHK v1 Scripts » | « TheArkive AHK v2 Scrpts » | « TheArkive on GitHub »
Re: JSON - load and dump arrays to/from JSON - AHK v1/2 - 2020/10/10 - a122
This script is really useful for me! On the latest v2 alpha, I am experiencing one minor issue: All boolean values are loaded as a string (either "true" or "false")
I've narrowed it down to the fact that AHK v2 does not return true when you call IsNumber on the strings "true" and "false". Additionally, using the expression when var is the string "true" or "false" throws an exception because AHK thinks you're trying to assign a value to a protected variable.
I had to change that block of code to this:
Edit: Come to think of it, the "null" check nested within IsNumber likely doesn't work either... my .json files just don't have null values AFAIK.
I've narrowed it down to the fact that AHK v2 does not return true when you call IsNumber on the strings "true" and "false". Additionally, using the expression
Code: Select all
%var% + 0
I had to change that block of code to this:
Code: Select all
if IsNumber(val) {
if IsInteger(val)
val += 0
else if IsFloat(val)
val += 0
else if (val == "null")
val := ""
else if is_key {
pos--, next := "#"
continue
}
} else if (val == "true" || val == "false") {
val := (val == "true")
}
Re: JSON - load and dump arrays to/from JSON - AHK v1/2 - 2020/10/10 - a122
@bmcclure
Thanks for the report!
I'll make the change in the OP soon, and of course give you credit. I'm surprised i missed that one
Thanks for the report!
I'll make the change in the OP soon, and of course give you credit. I'm surprised i missed that one
« AHK Portable Installer » | « CallTipsForAll » | « TheArkive AHK v1 Scripts » | « TheArkive AHK v2 Scrpts » | « TheArkive on GitHub »
Re: JSON - load and dump arrays to/from JSON - AHK v1/2 - 2020/10/10 - a122
Awesome, thank you!
Just to confirm, are you still working on the change or is it already done?
It looks like the change is in the OP, however it (and the "null" string check) are still nested within the IsNumber() conditional. I don't think those two checks will work right until they're moved out to the same level as that IsNumber conditional.
Just to confirm, are you still working on the change or is it already done?
It looks like the
Code: Select all
val := (val == "true")
Re: JSON - load and dump arrays to/from JSON - AHK v1/2 - 2020/10/10 - a122
@bmcclure
Yep you're right. Fixed.
I just removed the IsNumber() check, not needed since the other types are already checked.
Yep you're right. Fixed.
I just removed the IsNumber() check, not needed since the other types are already checked.
« AHK Portable Installer » | « CallTipsForAll » | « TheArkive AHK v1 Scripts » | « TheArkive AHK v2 Scrpts » | « TheArkive on GitHub »
Re: JSON - load and dump arrays to/from JSON - AHK v1/2 - 2021/03/08 - a128
2021/03/08
- Changed ByRef src to just src for Jxon_load()
Given the new VarRef, and how it is handled, it throws an error unless you explicitly pass a &VarRef. I didn't really see how passing a VarRef in this case would be beneficial so for now it is removed. - Removed some "code noise" that were remnants from the old code that no longer made sense or did anything, mostly commented stuff
« AHK Portable Installer » | « CallTipsForAll » | « TheArkive AHK v1 Scripts » | « TheArkive AHK v2 Scrpts » | « TheArkive on GitHub »
Re: JSON Serializer - AHK v1/2 - 2021/04/19 - a131
referring to the v1 script:
newlines, tabs, and carriage return all get an extra "\" prefixed to them. ie. \\n
Is this intentional behavior? It is caused from the ordering of your StrReplace calls in the Dump function.
changing the order will fix it if it is not intentional
newlines, tabs, and carriage return all get an extra "\" prefixed to them. ie. \\n
Is this intentional behavior? It is caused from the ordering of your StrReplace calls in the Dump function.
Code: Select all
Else {
obj := StrReplace(obj,"`t","\t")
obj := StrReplace(obj,"`r","\r")
obj := StrReplace(obj,"`n","\n")
obj := StrReplace(obj,"`b","\b")
obj := StrReplace(obj,"`f","\f")
obj := StrReplace(obj,"\","\\")
obj := StrReplace(obj,"/","\/")
obj := StrReplace(obj,q,"\" q)
return q obj q
}
Code: Select all
Else {
obj := StrReplace(obj,"\","\\")
obj := StrReplace(obj,"`t","\t")
obj := StrReplace(obj,"`r","\r")
obj := StrReplace(obj,"`n","\n")
obj := StrReplace(obj,"`b","\b")
obj := StrReplace(obj,"`f","\f")
obj := StrReplace(obj,"/","\/")
obj := StrReplace(obj,q,"\" q)
return q obj q
}
Re: JSON Serializer - AHK v1/2 - 2021/04/19 - a131
@dd900
That is definitely not intentional. Thanks for the info.
I can't believe I didn't come across this issue before.
I'll fix it soon.
That is definitely not intentional. Thanks for the info.
I can't believe I didn't come across this issue before.
I'll fix it soon.
« AHK Portable Installer » | « CallTipsForAll » | « TheArkive AHK v1 Scripts » | « TheArkive AHK v2 Scrpts » | « TheArkive on GitHub »
Re: JSON Serializer - AHK v1/2 - 2021/04/19 - a131
I actually just ran into another issue. If the value of a key is empty the script will throw an error when doing Jxon_Load because quotes are not being added to empty values.
ie.
coco's result
,"Genres":"",
your script result
,"Genres":, this throws an error
I can skip empty values in code, but I'm assuming this is also unintentional behavior.
ie.
coco's result
,"Genres":"",
your script result
,"Genres":, this throws an error
I can skip empty values in code, but I'm assuming this is also unintentional behavior.
Re: JSON Serializer - AHK v1/2 - 2021/04/19 - a131
@dd900
Yah that is also unintentional. Thanks again.
Adding that to the list.
Yah that is also unintentional. Thanks again.
Adding that to the list.
« AHK Portable Installer » | « CallTipsForAll » | « TheArkive AHK v1 Scripts » | « TheArkive AHK v2 Scrpts » | « TheArkive on GitHub »
Re: JSON Serializer - AHK v1/2 - 2021/04/19 - a131
Update: 2021/05/03
- fixed incorrect additional escaping (ie. \n to \\n) ... (both AHK v1 and v2)
- fixed zero-length strings showing up as blank instead of "" on jxon_dump() ... (only affected AHK v1)
« AHK Portable Installer » | « CallTipsForAll » | « TheArkive AHK v1 Scripts » | « TheArkive AHK v2 Scrpts » | « TheArkive on GitHub »
Re: JSON Serializer - 2021/06/21 - beta.1
I catch the error:
On the empty key name:
Re: JSON Serializer - 2021/06/21 - beta.1
Yes, it is written this way to throw an error on a blank key, or on any object that is not an [array] or a {Map}. This code was in the original script written by coco.
EDIT:
If you want to change it, remove the || (k == ""):
Code: Select all
Line #179-180
if IsObject(k) || (k == "")
throw Error("Invalid object key.", -1, k ? Format("<Object at 0x{:p}>", ObjPtr(obj)) : "<blank>")
EDIT:
If you want to change it, remove the || (k == ""):
Code: Select all
if IsObject(k)
throw Error("Invalid object key.", -1, k ? Format("<Object at 0x{:p}>", ObjPtr(obj)) : "<blank>")
« AHK Portable Installer » | « CallTipsForAll » | « TheArkive AHK v1 Scripts » | « TheArkive AHK v2 Scrpts » | « TheArkive on GitHub »
Re: JSON Serializer - 2021/06/21 - beta.1
First of all thank you for your work @TheArkive! I have created a fork that is able to serialize/deserialize non-Map/non-Array Objects as well. The limitation is for Classes to have constructor that is able to be executed without parameters, which is used in deserializer to create it's objects.
You might find it useful. Here's the fork address: https://github.com/buliasz/JXON_ahk2
You might find it useful. Here's the fork address: https://github.com/buliasz/JXON_ahk2
Re: JSON Serializer - 2021/06/21 - beta.1
@buliasz
Good stuff thanks for posting. I'll check it out.
Good stuff thanks for posting. I'll check it out.
« AHK Portable Installer » | « CallTipsForAll » | « TheArkive AHK v1 Scripts » | « TheArkive AHK v2 Scrpts » | « TheArkive on GitHub »
Re: JSON Serializer - 2021/11/05 - beta.1
2021/11/05
- Changed some "strings" to 'strings' so a separate var for Chr(34) (") is unnecessary.
- Fixed an issue where "\" in an item name was not properly processed on dump causing an error on load.
« AHK Portable Installer » | « CallTipsForAll » | « TheArkive AHK v1 Scripts » | « TheArkive AHK v2 Scrpts » | « TheArkive on GitHub »
Re: JSON Serializer - 2021/11/05 - beta.1
Hi, how I determine Lenght() ? I have a json array and i need to know the lenght of it to do a loop.. thanks.
Re: JSON Serializer - 2021/11/05 - beta.1
@Noblish
You must load the text into a var with var := FileRead("file.txt")
Then you use arr := json_load(&var) to load to an array.
Then you use normal ahk syntax ... msgbox "array length: " arr.Length
You must load the text into a var with var := FileRead("file.txt")
Then you use arr := json_load(&var) to load to an array.
Then you use normal ahk syntax ... msgbox "array length: " arr.Length
Code: Select all
var := FileRead("path\to\file.txt")
arr := json_load(&var)
msgbox "array length: " arr.Length
« AHK Portable Installer » | « CallTipsForAll » | « TheArkive AHK v1 Scripts » | « TheArkive AHK v2 Scrpts » | « TheArkive on GitHub »
Return to “Scripts and Functions (v2)”
Who is online
Users browsing this forum: MrDoge and 25 guests