Skip to content

Commit

Permalink
Update README for new interface
Browse files Browse the repository at this point in the history
  • Loading branch information
G33kDude committed Sep 8, 2021
1 parent 691f8df commit a50643e
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,23 @@ planned, but may not be implemented any time soon.
Converting an AHK Object to JSON:

```ahk
#Include <cJson>
#Include <JSON>
; Create an object with every supported data type
obj := ["abc", 123, {"true": true, "false": false, "null": ""}, [cJson.true, cJson.false, cJson.null]]
; Convert to JSON
MsgBox, % cJson.Dumps(obj) ; Expect: ["abc", 123, {"false": 0, "null": "", "true": 1}, [true, false, null]]
MsgBox, % JSON.Dump(obj) ; Expect: ["abc", 123, {"false": 0, "null": "", "true": 1}, [true, false, null]]
```

Converting JSON to an AHK Object:

```ahk
#Include <cJson>
#Include <JSON>
; Create some JSON
json = ["abc", 123, {"true": 1, "false": 0, "null": ""}, [true, false, null]]
obj := cJson.Loads(json)
str = ["abc", 123, {"true": 1, "false": 0, "null": ""}, [true, false, null]]
obj := JSON.Loads(str)
MsgBox, % obj[1] ; abc
MsgBox, % obj[2] ; 123
Expand All @@ -43,9 +43,9 @@ MsgBox, % obj[3].true ; 1
MsgBox, % obj[3].false ; 0
MsgBox, % obj[3].null ; *nothing*
MsgBox, % obj[4, 1] == cJson.True ; 1
MsgBox, % obj[4, 2] == cJson.False ; 1
MsgBox, % obj[4, 3] == cJson.Null ; 1
MsgBox, % obj[4, 1] ; 1
MsgBox, % obj[4, 2] ; 0
MsgBox, % obj[4, 3] == JSON.Null ; 1
```

## Notes
Expand All @@ -61,16 +61,16 @@ default, cJson will behave according to the following table:
|---------------|------------|---------------|
| `true` | `1` | `1` * |
| `false` | `0` | `0` * |
| `null` | N/A | `cJson.Null` |
| `null` | N/A | `JSON.Null` |
| `0.5`| `"0.5"` | `0.500000` |
| `0.5+0`| `0.500000` | N/A |
| `cJson.True` | `true` | N/A |
| `cJson.False` | `false` | N/A |
| `cJson.Null` | `null` | N/A |
| `JSON.True` | `true` | N/A |
| `JSON.False` | `false` | N/A |
| `JSON.Null` | `null` | N/A |

\* To avoid type data loss when decoding `true` and `false`, the class property
`cJson.BoolsAsInts` can be set `:= true`. Once set, boolean true and false
will decode to `cJson.True` and `cJson.False` respectively.
`JSON.BoolsAsInts` can be set `:= true`. Once set, boolean true and false
will decode to `JSON.True` and `JSON.False` respectively.

† Pure floats, as generated by an expression, will encode as floats. Hybrid
floats that contain a string buffer will encode as strings. Floats hard-coded
Expand Down

0 comments on commit a50643e

Please sign in to comment.