To json
Jump to navigation
Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
Function Syntax
string to_json(aggregate input )
- input can actually be of any datatype, but it is unlikely to work unless it is a simple map.
Converts a simple map into a JSON string.
Code Sample
Converts the player's inventory into JSON data.
print( to_json( get_inventory() ) )
Will print inventory in this format:
- { ""DRINK ME" potion" : 1, "astral energy drink" : 2, "astral mask" : 1, "baconstone" : 2, "bag of GORF" : 1, "bag of GORP" : 1, "Barney's rake" : 1, "beery blood" : 5, "bitchin' meatcar" : 1, "bone flute" : 1, "boss brain" : 1, "bottle of rum" : 1, "bowl of cottage cheese" : 2, "box of sunshine" : 1, "brick" : 135, "Camp Scout pup tent" : 1, "can of sardines" : 1, "cast" : 1, "chef's hat" : 2, "Clan VIP Lounge key" : 1, "Cobb's Knob lab key" : 1, "comfy pillow" : 1, "continuum transfunctioner" : 1, "CSA cheerfulness ration" : 1, "CSA fire-starting kit" : 1, "CSA obedience grenade" : 1, "CSA scoutmaster's "water"" : 1, "cursed microwave" : 1, "cursed pony keg" : 1, "dented spoon" : 2, "detuned radio" : 1, "deviled egg" : 1, "dingy dinghy" : 1, "disassembled clover" : 1, "disintegrating quill pen" : 1, "DNA extraction syringe" : 1, "dried face" : 1, "empty Rain-Doh can" : 1, "enchanted bean" : 1, "Evilometer" : 1, "eyepatch" : 1, "finger exerciser" : 1, "flaming crutch" : 1, "flaregun" : 2, "GameInformPowerDailyPro walkthru" : 1, "Gene Tonic: Dude" : 1, "Gene Tonic: Plant" : 1, "Gene Tonic: Undead" : 1, "glass of goat's milk" : 1, "gnomish housemaid's kgnee" : 1, "good brain" : 38, "grey cube" : 1, "gunpowder burrito" : 5, "gym membership card" : 1, "hamethyst" : 1, "high-calorie sugar substitute" : 1, "hilarious comedy prop" : 1, "hot plate" : 1, "hot wing" : 5, "hunter brain" : 1, "imp air" : 2, "Imp Ale" : 10, "imp unity ring" : 1, "infernal insoles" : 1, "Jolly Roger charrrm bracelet" : 1, "Knob Goblin firecracker" : 1, "Knob Goblin harem pants" : 1, "Knob Goblin harem veil" : 1, "Knob Goblin pants" : 1, "Knob Goblin perfume" : 1, "Knob Goblin scimitar" : 1, "Knob Goblin tongs" : 1, "leather mask" : 1, "left bear arm" : 1, "lihc eye" : 4, "lihc face" : 1, "meat stack" : 3, "military-grade fingernail clippers" : 1, "moxie weed" : 1, "nail file" : 1, "observational glasses" : 1, "old sweatpants" : 1, "pat of butter" : 1, "porquoise" : 1, "Rain-Doh black box" : 1, "Rain-Doh blue balls" : 1, "Rain-Doh green lantern" : 1, "Rain-Doh indigo cup" : 1, "Rain-Doh orange agent" : 1, "Rain-Doh red wings" : 1, "Rain-Doh violet bo" : 1, "Rain-Doh yellow laser gun" : 1, "right bear arm" : 1, "safarrri hat" : 1, "scroll of Protection from Bad Stuff" : 1, "scroll of Puddingskin" : 1, "Scuba Snack" : 1, "Shivering Chèvre" : 1, "skeleton bone" : 1, "snifter of thoroughly aged brandy" : 1, "soft green echo eyedrop antidote" : 1, "spooky stick" : 2, "steel lasagna" : 1, "stone wool" : 3, "stuffed Baron von Ratsworth" : 1, "stuffed hand turkey" : 1, "stuffed shoulder parrot" : 1, "swashbuckling pants" : 1, "Victor, the Insult Comic Hellhound Puppet" : 1, "viking helmet" : 4, "votive candle" : 1, "water purification pills" : 1, "whalebone corset" : 1, "whole turkey leg" : 1, "Ze™ goggles" : 1 }
See Also
Special
It is a known bug that quotes are not escaped in the JSON string which will cause a serious problem if the output from the previous example is actually used. Be aware!