Sean Mackesey Sean Mackesey - 1 month ago 10
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

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

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