Mercurial > vim
comparison runtime/doc/eval.txt @ 7967:45ea5ebf3a98 v7.4.1279
commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Feb 7 19:19:53 2016 +0100
patch 7.4.1279
Problem: jsonencode() is not producing strict JSON.
Solution: Add jsencode() and jsdecode(). Make jsonencode() and jsondecode()
strict.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sun, 07 Feb 2016 19:30:05 +0100 |
parents | b74549818500 |
children | 78106b0f2c56 |
comparison
equal
deleted
inserted
replaced
7966:79c5a86fcdfe | 7967:45ea5ebf3a98 |
---|---|
1954 items( {dict}) List key-value pairs in {dict} | 1954 items( {dict}) List key-value pairs in {dict} |
1955 job_start({command} [, {options}]) Job start a job | 1955 job_start({command} [, {options}]) Job start a job |
1956 job_status({job}) String get the status of a job | 1956 job_status({job}) String get the status of a job |
1957 job_stop({job} [, {how}]) Number stop a job | 1957 job_stop({job} [, {how}]) Number stop a job |
1958 join( {list} [, {sep}]) String join {list} items into one String | 1958 join( {list} [, {sep}]) String join {list} items into one String |
1959 jsdecode( {string}) any decode JS style JSON | |
1960 jsencode( {expr}) String encode JS style JSON | |
1959 jsondecode( {string}) any decode JSON | 1961 jsondecode( {string}) any decode JSON |
1960 jsonencode( {expr}) String encode JSON | 1962 jsonencode( {expr}) String encode JSON |
1961 keys( {dict}) List keys in {dict} | 1963 keys( {dict}) List keys in {dict} |
1962 len( {expr}) Number the length of {expr} | 1964 len( {expr}) Number the length of {expr} |
1963 libcall( {lib}, {func}, {arg}) String call {func} in library {lib} with {arg} | 1965 libcall( {lib}, {func}, {arg}) String call {func} in library {lib} with {arg} |
2437 | 2439 |
2438 < The number can be used with |CTRL-W_w| and ":wincmd w" | 2440 < The number can be used with |CTRL-W_w| and ":wincmd w" |
2439 |:wincmd|. | 2441 |:wincmd|. |
2440 Only deals with the current tab page. | 2442 Only deals with the current tab page. |
2441 | 2443 |
2442 | |
2443 byte2line({byte}) *byte2line()* | 2444 byte2line({byte}) *byte2line()* |
2444 Return the line number that contains the character at byte | 2445 Return the line number that contains the character at byte |
2445 count {byte} in the current buffer. This includes the | 2446 count {byte} in the current buffer. This includes the |
2446 end-of-line character, depending on the 'fileformat' option | 2447 end-of-line character, depending on the 'fileformat' option |
2447 for the current buffer. The first character has byte count | 2448 for the current buffer. The first character has byte count |
2686 {address} has the form "hostname:port", e.g., | 2687 {address} has the form "hostname:port", e.g., |
2687 "localhost:8765". | 2688 "localhost:8765". |
2688 | 2689 |
2689 If {argdict} is given it must be a |Dictionary|. The optional | 2690 If {argdict} is given it must be a |Dictionary|. The optional |
2690 items are: | 2691 items are: |
2691 mode "raw" or "json". | 2692 mode "raw", "js" or "json". |
2692 Default "json". | 2693 Default "json". |
2693 callback function to call for requests with a zero | 2694 callback function to call for requests with a zero |
2694 sequence number. See |channel-callback|. | 2695 sequence number. See |channel-callback|. |
2695 Default: none. | 2696 Default: none. |
2696 waittime Specify connect timeout as milliseconds. | 2697 waittime Specify connect timeout as milliseconds. |
4379 let lines = join(mylist, "\n") . "\n" | 4380 let lines = join(mylist, "\n") . "\n" |
4380 < String items are used as-is. |Lists| and |Dictionaries| are | 4381 < String items are used as-is. |Lists| and |Dictionaries| are |
4381 converted into a string like with |string()|. | 4382 converted into a string like with |string()|. |
4382 The opposite function is |split()|. | 4383 The opposite function is |split()|. |
4383 | 4384 |
4385 jsdecode({string}) *jsdecode()* | |
4386 This is similar to |jsondecode()| with these differences: | |
4387 - Object key names do not have to be in quotes. | |
4388 - Empty items in an array (between two commas) are allowed and | |
4389 result in v:none items. | |
4390 | |
4391 jsencode({expr}) *jsencode()* | |
4392 This is similar to |jsonencode()| with these differences: | |
4393 - Object key names are not in quotes. | |
4394 - v:none items in an array result in an empty item between | |
4395 commas. | |
4396 For example, the Vim object: | |
4397 [1,v:none,{"one":1}],v:none ~ | |
4398 Will be encoded as: | |
4399 [1,,{one:1},,] ~ | |
4400 While jsonencode() would produce: | |
4401 [1,null,{"one":1},null] ~ | |
4402 This encoding is valid for JavaScript. It is more efficient | |
4403 than JSON, especially when using an array with optional items. | |
4404 | |
4405 | |
4384 jsondecode({string}) *jsondecode()* | 4406 jsondecode({string}) *jsondecode()* |
4385 This parses a JSON formatted string and returns the equivalent | 4407 This parses a JSON formatted string and returns the equivalent |
4386 in Vim values. See |jsonencode()| for the relation between | 4408 in Vim values. See |jsonencode()| for the relation between |
4387 JSON and Vim values. | 4409 JSON and Vim values. |
4388 The decoding is permissive: | 4410 The decoding is permissive: |
4389 - A trailing comma in an array and object is ignored. | 4411 - A trailing comma in an array and object is ignored. |
4390 - An empty item in an array, two commas with nothing or white | |
4391 space in between, results in v:none. | |
4392 - When an object member name is not a string it is converted | |
4393 to a string. E.g. the number 123 is used as the string | |
4394 "123". | |
4395 - More floating point numbers are recognized, e.g. "1." for | 4412 - More floating point numbers are recognized, e.g. "1." for |
4396 "1.0". | 4413 "1.0". |
4397 The result must be a valid Vim type: | 4414 The result must be a valid Vim type: |
4398 - An empty object member name is not allowed. | 4415 - An empty object member name is not allowed. |
4399 - Duplicate object member names are not allowed. | 4416 - Duplicate object member names are not allowed. |
4411 used recursively: [] | 4428 used recursively: [] |
4412 Dict as an object (possibly null); when | 4429 Dict as an object (possibly null); when |
4413 used recursively: {} | 4430 used recursively: {} |
4414 v:false "false" | 4431 v:false "false" |
4415 v:true "true" | 4432 v:true "true" |
4416 v:none nothing | 4433 v:none "null" |
4417 v:null "null" | 4434 v:null "null" |
4418 Note that using v:none is permitted, although the JSON | 4435 Note that using v:none is permitted, although the JSON |
4419 standard does not allow empty items. This can be useful for | 4436 standard does not allow empty items. This can be useful for |
4420 omitting items in an array: | 4437 omitting items in an array: |
4421 [0,,,,,5] ~ | 4438 [0,,,,,5] ~ |