Sean Mackesey Sean Mackesey - 1 year ago 119
JSON Question

Export a Vimscript Dictionary as JSON

I have a found a plugin that enables Vim to parse JSON. I need to export VimScript dictionaries as JSON. Currently I am just using:

let str = string(dict)
substitute(str, "'", '"', 'g')

This is working but is bound to break when I run into dictionaries with embedded quotes. What is a better way?

Answer Source

The WebAPI.vim plugin has a JSON parser and encoder:

:let jsonString = webapi#json#encode({...})
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download