Page 1 of 1

v2 object issues

Posted: 25 Aug 2023, 20:48
by Gate
In my http request to access an important API, I need to send in a JSON object with header: { x-api-key : "myapikey"}

I've always built the object in AHK first and then parsed it into JSON with a function.

New AHKv2 decided that 'x-api-key' is an 'Invalid property name in object literal'.

Come on... that's crazy. I need to be able to make an object with a '-' in the key name. Can this be fixed or will I be forever using AHK v1?



I'm doing everything I can to make a workaround... still no luck... It's giving me errors that make zero sense.

Error: This value of type "Object" has no property named "__Item".

003: p := {}
▶ 004: p["x-api-key"] := 1
006: MsgBox(p["x-api-key"])
008: ExitApp()

Re: v2 object issues

Posted: 25 Aug 2023, 20:58
by Gate
If there's no fix, can this be moved to AHK v2 bugs. This is serious. I can't use v2 until this is fixed.

It's frustrating to run into an error like this after spending 20hrs learning the new system and rewriting key functions in the new syntax, only to find I can't use any of this for my primary use case because of some overly strict syntax requirements.

Re: v2 object issues  Topic is solved

Posted: 25 Aug 2023, 21:26
by 20170201225639
Use Map (see: https://www.autohotkey.com/docs/v2/v2-changes.htm#objects-misc)

Code: Select all

p := Map()
p["x-api-key"] := 1
006: MsgBox(p["x-api-key"])
008: ExitApp()

Re: v2 object issues

Posted: 25 Aug 2023, 21:49
by Gate
Okay the workaround for map is working thanks. It's too bad I can't use the regular object notation though { k : v }, I'm going to have to rewrite a bunch of code.

Re: v2 object issues

Posted: 25 Aug 2023, 22:32
by 20170201225639
Yes, this is a big part of the process of converting from v1 to v2. But IMO it's worth it. It makes the code less prone to breaking.

For previous discussions see viewtopic.php?t=67213&start=40