JSON library of the Chaos langauge. You can install this spell with:
occultist install json
and import it with:
import json
Returns all the keys in dictionary d
.
kaos> dict a = {'a': 1, 'b': 2, 'c': 3}
kaos> json.keys(a)
['a', 'b', 'c']
Returns all the values in dictionary d
.
kaos> dict a = {'a': 1, 'b': 2, 'c': 3}
kaos> json.values(a)
[1, 2, 3]
Exchanges all keys with their associated values in dictionary d
.
kaos> dict a = {'a': 1, 'b': 2, 'c': 3}
kaos> json.flip(a)
{'1': 'a', '2': 'b', '3': 'c'}
Returns a string containing the JSON representation of dictionary d
.
kaos> dict a = {'a': 1, 'b': 2, 'c': 3}
kaos> str json_encoded = json.encode(a)
kaos> json_encoded
{"a": 1, "b": 2, "c": 3}
Turns JSON string json
into a dictionary that Chaos language understands.
kaos> str b = "{'d': 4, 'e': 5, 'f': 6}"
kaos> dict json_decoded = json.decode(b)
kaos> json_decoded
{'d': 4, 'e': 5, 'f': 6}
Searches the dictionary haystack
for a given value needle
and returns the first corresponding key if successful. Returns an empty string ""
if unsuccessful.
kaos> dict a = {'a': 1, 'b': 2, 'c': 3}
kaos> json.search(a, 2)
b
kaos> dict c = {'a': 'foo', 'b': 'bar', 'c': 'baz'}
kaos> json.search(c, 'baz')
c
kaos> json.search(c, 'jazz')
Replaces all occurrences of the needle
with the replacement
in dictionary haystack
.
kaos> dict a = {'a': 1, 'b': 2, 'c': 3}
kaos> json.replace(a, 2, 9)
{'a': 1, 'b': 9, 'c': 3}
kaos> dict b = {'a': 'foo', 'b': 'bar', 'c': 'baz'}
kaos> json.replace(b, 'bar', 'gar')
{'a': 'foo', 'b': 'gar', 'c': 'baz'}
Counts all the keys in given dictionary d
.
kaos> dict a = {'a': 1, 'b': 2, 'c': 3}
kaos> json.count(a)
3