List tools helps you convert effortlessly between common list formats, such as JSON
, CSV
, YAML
or XML
and programming languages such as SQL
, JavaScript
, TypeScript
, PHP
or C
(see Supported Formats).
Simply select any data source and run the command List Tools: Convert multiple columns to object list
to convert between formats.
Features
- Extract list data from data sources, such as
JSON
, CSV
, YAML
or XML
- Extract simple or object list data from programming languages, such as
JavaScript
, TypeScript
, PHP
or C
- Convert simple or object lists between data sources and programming languages
- Extract single or multiple columns from object lists
Input Formats |
|
Output Formats |
|
⇄ |
|
|
⇄ |
|
|
⇄ |
|
|
⇄ |
|
|
⇄ |
|
|
⇄ |
|
|
⇄ |
|
|
⇄ |
|
|
⇄ |
|
|
⇄ |
|
|
⇄ |
|
|
⇄ |
|
|
⇄ |
|
|
⇄ |
|
|
⇄ |
|
Commands
List Tools: Convert single column to simple list
- Extract a single column from your current selection
- Convert them into a simple list in the target language
List Tools: Convert multiple columns to object list
- Extract multiple columns from your current selection
- Convert them into an object list in the target language
List Tools: Convert single column to simple list (pretty print)
- Same as
List Tools: Convert single column to simple list
with pretty printing enabled
List Tools: Convert multiple columns to object list (pretty print)
- Same as
List Tools: Convert multiple columns to object list
with pretty printing enabled
List Tools: Convert single column to simple list (without pretty print)
- Same as
List Tools: Convert single column to simple list
with pretty printing disabled
List Tools: Convert multiple columns to object list (without pretty print)
- Same as
List Tools: Convert multiple columns to object list
with pretty printing disabled
List Tools: Extract columns from object list
- Extract a single column from your current selection
- Keep the current language and remove deselected columns from list
List Tools: Repeat last action
- Repeat the last action (Must be the same language as the previous action)
Settings
The pretty printing level can be set on a per-language basis by using vscode's language-specific selector:
"[json]": {
"list-tools.prettyPrint": 1
}
The level matches the indentation level for most languages, specifying -1
equates to an infinite depth:
// "list-tools.prettyPrint": -1
// equivalent to "list-tools.prettyPrint": 2
[
{
"city": "Tokyo",
"country": "Japan",
"population": 37732000,
}
]
// "list-tools.prettyPrint": 1
[
{ "city": "Tokyo", "country": "Japan", "population": 37732000 }
]
// "list-tools.prettyPrint": 0
[{"city":"Tokyo","country":"Japan","population":37732000}]
It is possible to add your own formats using the internal descriptors used to generate the shipped output languages. You can either create the format from scratch or use an existing format as a base. For example, output in XML using properties instead of elements could look like this:
{
"list-tools.additionalFormats": {
"xml-attributes": {
"name": "XML with Attributes",
"objectList": {
"base": "xml",
"delimiter": " ", // Override the delimiter to separaten items
"itemFormat": {
"assignmentOperator": "=", // Attribute assignment
"assignmentOperatorSpaced": "=", // There is no spaced version in XML
"enclosure": {
"start": "<item ", // Override `<item></item>` enclosure
"end": "/>",
},
"keyEnclosure": [
{
"id": "bracket-keys", // Disable enclosing keys in `<{key}></{key}>`
"disabled": true
}
],
"valueEnclosure": "\"", // Quote all values
},
}
}
}
}
Parameters
Parameters can be accessed using the default javascript template string syntax ${<key>}
.
The <key>
is a key from a list of supported parameters, or when enclosed in "
or '
is used as-is.
The extension has some additional features, such as numeric modifiers and optional repeats:
Modifiers can be used in the format ${<key> [modifier] <value>}
(spaces are optional). Only a single modifier (except for multiple .
) is supported. Supported Modifiers:
+
: ${<key> + <value>}
=> casts both parameter value and the <value>
to a number and adds them together
-
: ${<key> - <value>}
=> casts both parameter value and the <value>
to a number and subtracts <value>
from the parameter value
*
: ${<key> * <value>}
=> casts both parameter value and the <value>
to a number and multiplies them
/
: ${<key> / <value>}
=> casts both parameter value and the <value>
to a number and divides the parameter value by <value>
%
: ${<key> % <value>}
=> casts both parameter value and the <value>
to a number and performs a module operation on them
.
: ${<key>.</key>.</key>}
=> used to access inner properties. This is the only modifier that can be repeated, though it cannot be combined with other modifiers.
It is possible to repeat a template or render it conditionally using the syntax $[<repeat>]*{<key> [modifier] <value>}
or $[<repeat>]?{<key> [modifier] <value>}
.
Inside []
additional modifiers can be used:
>
: ${<key> > <value>}
=> checks if the parameter value is larger than <value>
and returns "true"
or "false"
<
: ${<key> < <value>}
=> checks if the parameter value is less than <value>
and returns "true"
or "false"
=
: ${<key> = <value>}
=> checks if the parameter value is equal to <value>
and returns "true"
or "false"
!
: ${<key> ! <value>}
=> checks if the parameter value is unequal <value>
and returns "true"
or "false"
To query the user for parameters, a parameters
property can be added to custom formats:
{
"objectList": {
"delimiter": "\n${separator}", /
"parameters": {
"separator": {
"type": "string",
"query": {
"prompt": "Add horizontal separators",
"options": {
// Parameters are keyed by the text display during the query
"Yes": "\\hline\n",
"Double": "\\hline\\hline\n",
"No": "",
}
}
}
}
}
}
Known Limitations
- data sources and programming languages must be in a valid format
- extraction from programming languages only works in cases with simple key-value pairs
- converting may lead to invalid syntax when special characters are involved
Contributing
Feel free to open pull request or issues with additional formats.
Have a look through src/providers/formats
for some examples.
This extension also supports localization through vscodes l10n, so l10n bundles are always welcome.
All bundles included in l10n/
will always be complete, so any of them can be used as a template.