cocobelgica / autohotkey-json Goto Github PK
View Code? Open in Web Editor NEWJSON module for AutoHotkey
JSON module for AutoHotkey
line 17 generates the last of three errors. Apparently Instr can't handle anything besides numeric literals or a variable. So the part -(StrLen(src)-pos+1) should be replaced by tmp, which should be filled on the line before
input_string := [{"city": "Montréal"}, {"city": "Vancouver"}]
cities := JSON.Load( input_string )
;;;
output_string := JSON.Dump( cities )
MsgBox, %output_string%
Result:
[{"city": "Montr\u00e9al"}, {"city": "Vancouver"}]
It has converted é
to \u00e9
Why? How can I avoid that?
Hi, could you please add the url to this repo right into the script's body and some email contact of yours (as the author) as well as the version and timestamp of latest change.
This would be handy: I use helluva ton of scripts and libs and I don't always remember where I took what from. And it's a PitA to check for scripts/libs updates, when a lib lacks that metainfo.
There is no issue. I only want to say thank you! What a comfortable tool I use.
I am using this library to pretty print the JSON. But it is order is changed alphabetically.
How to preserve the original order?
I'm storing a dictionary-like structure where I need to check if a color exists in a large list of colors. Best way to do that is like if (colors["0x680000"])
so I generate an object like that but I need to save the object, so I export to JSON. Problem is, during the export, the hex values are treated as numbers (even though they're property names, and could probably safely be treated as strings) so they're converted to decimal. I need to figure out a way to store the object keys as strings rather than numbers so they stay in the format "0x680000" : {}
in the JSON file.
I'm encountering a compile-time error when including JSON.ahk.
JSON.ahk (44) : ==> Missing comma
Specifically: Call(self, ByRef text, reviver:="")
I am using AHK V2.
Hi @cocobelgica. I'm wondering if you'd be interested in publishing AutoHotkey-JSON as an ahkpm package?
ahkpm is a package manager built specifically for AutoHotkey libraries.
I've written a guide on how to publish ahkpm packages and it likely wouldn't take much time at all.
The main thing I noticed that you might need to change is to start tagging new versions with the appropriate semantic version number. e.g. git tag 1.3.18
.
I'd be happy to open up a PR adding the ahkpm.json
file if you're interested.
In my script i have 2 JSON.Load() function, the 1st one works and the 2nd don't. Similar to JSON.Dump... If i use more than 1 JSON function then all except the first one wont work.
Example:
content is a json string
json := JSON.Load(content)
invoice := json.invoice
msgbox, % invoice.Length () ; -> this work, shows the right length
line := StrSplit(sp, " ")
new := {}
new.sp := line[1]
new.sl := line[2]
view := JSON.Dump(new)
msgbox, % view ; -> this dont work, doesnt show anything
if i delete this line: json := JSON.Load(content)
then the JSON.Dump work
Thank you.
STR:
Actual result:
2 and 3 got transformed to 'null'.
Expected result:
They should get saved as strings.
1 and 0 get transformed to 'true' and 'false' respectively.
When I have a JSON string where the sum of the length of all keys is very large (for my object layout, a list of objects, it is somewhere over 10 000 characters, for flat object it should be higher), the result of JSON.Load is an object that cannot be iterated with the following construct
for k, v in object {
}
but if I check the capacity of the object it is 60.
Probably it is a limitation of ahk, as I do not see any obvious problem in your code.
How large can objects grow in ahk?
The current code is not compatible with the most recent v2 build. Lines 239 and 279 would need to get rid of the % as expressions are standard now.
could i get any example code
Jxon_Load:
; in v1.1, true,false,A_PtrSize,A_IsUnicode,A_Index,A_EventInfo,
; SOMETIMES return strings due to certain optimizations. Since it
; is just 'SOMETIMES', numerify to be consistent w/ v2.0-a
else if (val == "true" || val == "false")
val := %value% + 0
Shouldn't %value%
be %val%
? This line caused an execution error for me in AHKv2
cant even run example file. it errors.
The parser consumes true and false but then dumps them as 1 and 0.
This is an issue in JSON strings that include both true/false and 1/0 values that are intended to represent different data types (boolean vs. numeric).
Technically this behavior makes sense if your program is fully insulated in AHK, because AHK stores and represents these values the same way internally, but if you're sharing the JSON file with other applications, the distinction between true/false and 1/0 can become meaningful.
The code change made in response to issue #4 is tangentially related.
How can I access objects with a / in the name?
"test/slash": "good",
Maybe I'm doing something wrong.
using AHK [1.1.35.00]
when I have this line:
#Include <JSON>
at the top of my ahk script I get an error when trying to load it, saying Error: Continuation section too long.
the error box gives me Line Text: which points to line 27 in JSON.ahk file.
I looked at this line and it is extremely long.
How can I work around this?
I know there is a continuation line section in the AHK documentation but it's way above my head and I don't understand enough to go messing around with myself.
Received JSON:
{"ok":true,"result":[{"update_id":91411951,"message":{"message_id":17826,"from":{"id":[Removed],"is_bot":false,"first_name":"[Removed]","last_name":"[Removed]","username":"[Removed]","language_code":"en"},"chat":{"id":[Removed],"first_name":"[Removed]","last_name":"[Removed]","username":"[Removed]","type":"private"},"date":1545984163,"text":"\ud83d\ude00"}}]}
The emoji sent is U+1F600 😀
Parsing this with
Update := JSON.Load(Json)
When i try to get Update.result[1].message.text
it returns ?0
is there a way to make it not parse unicode?
What a custom object factory can solve:
Implementing:
Add a static ObjectFactory
property to JSON class, defaulting to Object
. Every time Load creates a new object, it uses the ObjectFactory value. If it has a __Class
property it calls new ObjectFactory
, otherwise it just calls ObjectFactory()
.
To set their own object factories users simply set the property to a custom class that is object-like i.e. it implements key Object methods such as HasKey
and _NewEnum
that JSON class uses. One particular example is this Scripting.Dictionary
class wrapper: forum link
I have successfully implemented this in a keyvalue parser library I'm using. I haven't shipped anything that uses it yet... but soon...
Last tested just now with AHK v 1.1.33.10
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.