Skip to content

rerodrigues/vscode-json-to-js

Repository files navigation

JSON to JS converter

Converts a JSON string into a valid JavaScript object

Using

Select a JSON string in the editor and in press Ctrl+Shift+J (⌘+⇧+J on Mac OS) or open the command pallete Ctrl+Shift+P (⌘+⇧+P on Mac OS) and type Convert JSON into JS object.

It is especially useful when you're using a linter with strict rules on code styling. eg.: ESLint + eslint-config-airbnb

Before (JSON) x After (JS object)

image

Options

You can customize the options in Settings / Extensions / JSON to JS converter. Below are the available options: (requires VSCode restart)

image

Add Trailing Commas

Adds a trailing comma in the end of every object or array keys. Makes the result object source control friendly. Default: True

Identation Size

Sets the number of spaces used in indentation. Default: 2

Keybinds

The default keybind to convert JSON strings into JS objects is Ctrl+Shift+J (⌘+⇧+J on Mac OS)

Release Notes

0.2.0

-- Option to add trailing commas -- Customizable indentation size -- Default keybing

0.1.1

-- Stability improvements

0.1.0

-- Initial Release