Help using json? Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
slimpickens
Posts: 9
Joined: 04 Jul 2017, 06:41

Help using json?

05 Jul 2017, 10:35

I want to read and update and Google Sheet using their API but I'm not familiar with using JSON in ahk.
This is what the json looks like when I query a cell value.

Code: Select all

{
  "range": "Sheet1!A2",
  "majorDimension": "ROWS",
  "values": [
    [
      "English"
    ]
  ]
}
Can anyone show me how to put that cell value into an ahk variable, and also how I do the reverse and add a variable into json to update a sheet?

Thanks :)
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Help using json?  Topic is solved

05 Jul 2017, 11:45

Here's an example:

Code: Select all

q:: ;JSON example

vText = ;continuation section
(
{
  "range": "Sheet1!A2",
  "majorDimension": "ROWS",
  "values": [
    [
      "English"
    ]
  ]
}
)

oArray := JSON.Load(vText) ;JSON string to AHK array

vOutput := ""
. oArray.range "`r`n"
. oArray.majorDimension "`r`n"
. oArray.values.1.1

oArray.values.1.1 := "NEW VALUE" ;change the value

MsgBox, % vText ;original JSON string
MsgBox, % vOutput ;values from AHK array
MsgBox, % vOutput2 := JSON.Dump(oArray,, 4) ;AHK array to JSON string
MsgBox, % vOutput2 := JSON.Dump(oArray) ;AHK array to JSON string

;note: the JSON library creates a string, where the keys are in alphabetical order

oArray := ""
return

;JSON 2.0 (and Jxon) - JSON lib for AutoHotkey - AutoHotkey Community
;https://autohotkey.com/boards/viewtopic.php?f=6&t=627
;GitHub - cocobelgica/AutoHotkey-JSON: JSON module for AutoHotkey
;https://github.com/cocobelgica/AutoHotkey-JSON
#Include, %A_ScriptDir%\Lib\JSON.ahk ;change or comment this out as appropriate
Here's another example (which is JSON, despite the title):
help converting text to CSV - AutoHotkey Community
https://autohotkey.com/boards/viewtopic ... 19#p155919
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA

Return to “Ask For Help”

Who is online

Users browsing this forum: leehere10, rakesha002, TAC109 and 32 guests