Sean Mackesey Sean Mackesey - 12 days ago 5x
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?


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

:let jsonString = webapi#json#encode({...})