Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/ddu_vim/deps.ts>fn.json_decode

Dark deno-powered UI framework for neovim/Vim
Go to Latest
function fn.json_decode
import { fn } from "https://deno.land/x/ddu_vim@v4.0.0/deps.ts";
const { json_decode } = fn;

This parses a JSON formatted string and returns the equivalent in Vim values. See json_encode() for the relation between JSON and Vim values. The decoding is permissive:

  • A trailing comma in an array and object is ignored, e.g. "[1, 2, ]" is the same as "[1, 2]".
  • Integer keys are accepted in objects, e.g. {1:2} is the same as {"1":2}.
  • More floating point numbers are recognized, e.g. "1." for "1.0", or "001.2" for "1.2". Special floating point values "Infinity", "-Infinity" and "NaN" (capitalization ignored) are accepted.
  • Leading zeroes in integer numbers are ignored, e.g. "012" for "12" or "-012" for "-12".
  • Capitalization is ignored in literal names null, true or false, e.g. "NULL" for "null", "True" for "true".
  • Control characters U+0000 through U+001F which are not escaped in strings are accepted, e.g. " " (tab character in string) for "\t".
  • An empty JSON expression or made of only spaces is accepted and results in v:none.
  • Backslash in an invalid 2-character sequence escape is ignored, e.g. "\a" is decoded as "a".
  • A correct surrogate pair in JSON strings should normally be a 12 character sequence such as "\uD834\uDD1E", but json_decode() silently accepts truncated surrogate pairs such as "\uD834" or "\uD834\u"

A duplicate key in an object, valid in rfc7159, is not accepted by json_decode() as the result must be a valid Vim type, e.g. this fails: {"a":"b", "a":"c"}

Can also be used as a method:

ReadObject()->json_decode()

Parameters

denops: Denops
string: unknown

Returns

Promise<unknown>