JSON editing in Visual Studio Code (2024)

JSON is a data format that is common in configuration files like package.json or project.json. We also use it extensively in Visual Studio Code for our configuration files. When opening a file that ends with .json, VS Code provides features to make it simpler to write or modify the file's content.

JSON editing in Visual Studio Code (1)

IntelliSense and validation

For properties and values, both for JSON data with or without a schema, we offer up suggestions as you type with IntelliSense. You can also manually see suggestions with the Trigger Suggestions command (⌃Space (Windows, Linux Ctrl+Space)).

We also perform structural and value verification based on an associated JSON schema giving you red squiggles. To disable validation, use the json.validate.enable setting.

JSON editing in Visual Studio Code (2)

Package and project dependencies

We also offer IntelliSense for specific value sets such as package and project dependencies in package.json, project.json, and bower.json.

Quick navigation

JSON files can get large and we support quick navigation to properties using the Go to Symbol command (⇧⌘O (Windows, Linux Ctrl+Shift+O)).

JSON editing in Visual Studio Code (3)

Hovers

When you hover over properties and values for JSON data with or without schema, we will provide additional context.

JSON editing in Visual Studio Code (4)

Formatting

You can format your JSON document using ⇧⌥F (Windows Shift+Alt+F, Linux Ctrl+Shift+I) or Format Document from the context menu.

Folding

You can fold regions of source code using the folding icons on the gutter between line numbers and line start. Folding regions are available for all object and array elements.

In addition to the default JSON mode following the JSON specification, VS Code also has a JSON with Comments (jsonc) mode. This mode is used for the VS Code configuration files such as settings.json, tasks.json, or launch.json. When in the JSON with Comments mode, you can use single line (//) as well as block comments (/* */) as used in JavaScript. The mode also accepts trailing commas, but they are discouraged and the editor will display a warning.

The current editor mode is indicated in the editor's Status Bar. Select the mode indicator to change the mode and to configure how file extensions are associated to modes. You can also directly modify the files.associations setting to associate file names or file name patterns to jsonc.

JSON schemas and settings

To understand the structure of JSON files, we use JSON schemas. JSON schemas describe the shape of the JSON file, as well as value sets, default values, and descriptions. The JSON support shipped with VS Code supports all draft versions from draft 4 to draft 7, with limited support for drafts 2019-09 and 2020-12.

Servers like JSON Schema Store provide schemas for most of the common JSON-based configuration files. However, schemas can also be defined in a file in the VS Code workspace, as well as the VS Code settings files.

The association of a JSON file to a schema can be done either in the JSON file itself using the $schema attribute, or in the User or Workspace settings (File > Preferences > Settings) under the property json.schemas.

VS Code extensions can also define schemas and schema mapping. That's why VS Code already knows about the schema of some well-known JSON files such as package.json, bower.json, and tsconfig.json.

Mapping in the JSON

In the following example, the JSON file specifies that its contents follow the CoffeeLint schema.

{ "$schema": "https://json.schemastore.org/coffeelint", "line_endings": "unix"}

Note that this syntax is VS Code-specific and not part of the JSON Schema specification. Adding the $schema key changes the JSON itself, which systems consuming the JSON might not expect, for example, schema validation might fail. If this is the case, you can use one of the other mapping methods.

Mapping in the User Settings

The following excerpt from User Settings shows how .babelrc files are mapped to the babelrc schema located on https://json.schemastore.org/babelrc.

"json.schemas": [ { "fileMatch": [ "/.babelrc" ], "url": "https://json.schemastore.org/babelrc" }]

Tip: In addition to defining a schema for .babelrc, also make sure that .babelrc is associated to the JSON language mode. This is also done in the settings using the files.association array setting.

Mapping to a schema in the workspace

To map a schema that is located in the workspace, use a relative path. In this example, a file in the workspace root called myschema.json will be used as the schema for all files ending with .foo.json.

"json.schemas": [ { "fileMatch": [ "**/*.foo.json" ], "url": "./myschema.json" }]

Mapping to a schema defined in settings

To map a schema that is defined in the User or Workspace settings, use the schema property. In this example, a schema is defined that will be used for all files named .myconfig.

"json.schemas": [ { "fileMatch": [ "/.myconfig" ], "schema": { "type": "object", "properties": { "name" : { "type": "string", "description": "The name of the entry" } } } }]

Mapping a schema in an extension

Schemas and schema associations can also be defined by an extension. Check out the jsonValidation contribution point.

File match syntax

The file match syntax supports the '*' wildcard. Also, you can define exclusion patterns, starting with '!'. For an association to match, at least one pattern needs to match and the last matching pattern must not be an exclusion pattern.

 "json.schemas": [ { "fileMatch": [ "/receipts/*.json", "!/receipts/*.excluded.json" ], "url": "./receipts.schema.json" } ]

Define snippets in JSON schemas

JSON schemas describe the shape of the JSON file, as well as value sets and default values, which are used by the JSON language support to provide completion proposals. If you are a schema author and want to provide even more customized completion proposals, you can also specify snippets in the schema.

The following example shows a schema for a key binding settings file defining a snippet:

{ "type": "array", "title": "Keybindings configuration", "items": { "type": "object", "required": ["key"], "defaultSnippets": [ { "label": "New keybinding", "description": "Binds a key to a command for a given state", "body": { "key": "$1", "command": "$2", "when": "$3" } } ], "properties": { "key": { "type": "string" } ... } }}

This is an example in a JSON schema:

JSON editing in Visual Studio Code (5)

Use the property defaultSnippets to specify any number of snippets for the given JSON object.

  • label and description will be shown in the completion selection dialog. If no label is provided, a stringified object representation of the snippet will be shown as label instead.
  • body is the JSON object that is stringified and inserted when the completion is selected by the user. Snippet syntax can be used inside strings literals to define tabstops, placeholders, and variables. If a string starts with ^, the string content will be inserted as-is, not stringified. You can use this to specify snippets for numbers and booleans.

Note that defaultSnippets is not part of the JSON schema specification but a VS Code-specific schema extension.

Use rich formatting in hovers

VS Code will use the standard description field from the JSON Schema specification in order to provide information about properties on hover and during autocomplete.

If you want your descriptions to support formatting like links, you can opt in by using Markdown in your formatting with the markdownDescription property.

{ "$schema": "http://json-schema.org/draft-07/schema#", "type": "object", "properties": { "name": { "type": "string", "description": "The name of the entry", "markdownDescription": "The name of the entry. [See the documentation](https://example.com)" } }}

Note that markdownDescription is not part of the JSON schema specification but a VS Code-specific schema extension.

Offline mode

json.schemaDownload.enable controls whether the JSON extension fetches JSON schemas from http and https.

A warning triangle will show in the status bar when the current editor would like to use schemas that cannot be downloaded.

09/05/2024

JSON editing in Visual Studio Code (2024)

FAQs

How do I edit json in VS Code? ›

You can also review and edit the settings.json file directly by opening it in the editor with the Preferences: Open User Settings (JSON) or Preferences: Open Workspace Settings (JSON) command in the Command Palette (Ctrl+Shift+P). Settings are written as JSON by specifying the setting ID and value.

How to edit json code? ›

Copy and paste your JSON file in the JSON editor, or load it from disk via the menu or via drag-and-drop. Then, you can edit the contents similar to how you use any text editor: enter new content with your keyboard, and right-click to open a context menu with actions like copy/paste, insert, remove.

How do I beautify json code in Visual Studio Code? ›

Formatting. You can format your JSON document using Ctrl+Shift+I or Format Document from the context menu.

How to view JSON file in VS Code? ›

install
  1. Open vscode and search extensions for 'json viewer'
  2. download.
  3. reload.
  4. Usage: open a file, Press F1 and run 'Open in json viewer' Run the command again on editor to update the view.
Aug 15, 2024

How to beautify a JSON file? ›

About JSON beautifier and how to use
  1. Copy the JSON code that you want to beautify and paste it into-on the input field.
  2. Click the Beautify button to initiate beautification.
  3. The tool will display the code in the output area. You can now view and copy the beautified code to use in your documentation or any application.

How to convert json to object in VS Code? ›

How To Use
  1. Select a valid JSON object in your editor (if nothing is selected then the whole file is checked)
  2. Choose Convert JSON to JS Object in the command palette ( Cmt/Ctrl+Shift+P )
Mar 15, 2017

How do I edit text in a JSON file? ›

Especially JSON files used as translation resources. You can use any text/code editor such as Visual Studio Code, Notepad, Notepad++, Sublime Text and others to open and edit JSON files. Alternatively, you can use an online editor to edit your JSON files.

How to make a correction in a JSON file? ›

You can open the *. json file in any plain text editor. It is possible to make changes to any of the sections in the file; however, be sure that you only change the data and not the field names. For example, the entry "name"::DB_Name" displays the name field for a source table in a defined endpoint.

How to change a value in a JSON file? ›

  1. 𝗨𝘀𝗶𝗻𝗴 𝗝𝗮𝘃𝗮𝗦𝗰𝗿𝗶𝗽𝘁 (Node. js)In JavaScript (Node. js environment), working with JSON files is straightforward using the built-in fs module.
  2. 𝗦𝘁𝗲𝗽𝘀:
  3. Read the JSON file.
  4. Parse the JSON data to manipulate it.
  5. Modify or add new data.
  6. Stringify the data back to JSON format.
  7. Write the updated data back to the JSON file.
Feb 8, 2023

How do you format code in VS Code? ›

VS Code has great support for source code formatting. The editor has two explicit format actions: Format Document (Ctrl+Shift+I) - Format the entire active file. Format Selection (Ctrl+K Ctrl+F) - Format the selected text.

How to edit .JSON files? ›

Procedure. In the Enterprise Explorer view, right-click your . json file or other file type that contains JSON code and select Open With > JSON Editor. You can compress JSON strings so that the strings display on one line with white space removed between JSON elements.

How do I launch JSON format in VS Code? ›

To create a launch.json file, select create a launch.json file in the Run start view. If you go back to the File Explorer view (Ctrl+Shift+E), you'll see that VS Code has created a .vscode folder and added the launch.json file to your workspace.

How to open package.json in Visual Studio Code? ›

VS Code Go to node_modules README

Open package. json, click on a dependency : hit F12 to navigate into this package's folder. hit CTRL+F12 to open this package's folder in explorer.

Where can I find launch.json in VS Code? ›

Visual Studio Code generates a launch.json (under a .vscode folder in your project) with almost all of the required information. To get started with debugging you need to fill in the program field with the path to the executable you plan to debug.

How do I open a JSON file? ›

Opening JSON files is far more straightforward than you might think; it is a very simple data structure that is entirely text-based — which is why it is limited to strings and numbers. Because of this, you can use any file opener to view a JSON file, such as notepads, text editors, and even command-line interfaces.

How to comment in a JSON file? ›

Workarounds to Add Comments in JSON

One straightforward method is to include comments as part of the JSON data by using a dedicated key, such as _comment or __note . This key will hold the comment string. This method is simple and keeps the comment close to the relevant data.

Top Articles
Python JSON – How to Convert a String to JSON
Closing an Option Position - The Options Playbook
Craigslist San Francisco Bay
Wordscapes Level 5130 Answers
Online Reading Resources for Students & Teachers | Raz-Kids
Math Playground Protractor
DL1678 (DAL1678) Delta Historial y rastreo de vuelos - FlightAware
سریال رویای شیرین جوانی قسمت 338
Hssn Broadcasts
Betonnen afdekplaten (schoorsteenplaten) ter voorkoming van lekkage schoorsteen. - HeBlad
How do you like playing as an antagonist? - Goonstation Forums
Gmail Psu
Best Suv In 2010
Suffix With Pent Crossword Clue
Lake Nockamixon Fishing Report
Georgia Vehicle Registration Fees Calculator
Weather Rotterdam - Detailed bulletin - Free 15-day Marine forecasts - METEO CONSULT MARINE
Whitefish Bay Calendar
Gia_Divine
Ahn Waterworks Urgent Care
Fsga Golf
Timeforce Choctaw
Seeking Arrangements Boston
Www Va Lottery Com Result
Craigslistodessa
Dark Entreaty Ffxiv
Maisons près d'une ville - Štanga - Location de vacances à proximité d'une ville - Štanga | Résultats 201
Best Restaurants Ventnor
100 Million Naira In Dollars
Citibank Branch Locations In Orlando Florida
Wcostream Attack On Titan
Netherforged Lavaproof Boots
Lichen - 1.17.0 - Gemsbok! Antler Windchimes! Shoji Screens!
Pickle Juiced 1234
拿到绿卡后一亩三分地
KITCHENAID Tilt-Head Stand Mixer Set 4.8L (Blue) + Balmuda The Pot (White) 5KSM175PSEIC | 31.33% Off | Central Online
The Complete Guide To The Infamous "imskirby Incident"
Vivek Flowers Chantilly
Latest Nigerian Music (Next 2020)
Housing Intranet Unt
Danielle Ranslow Obituary
Executive Lounge - Alle Informationen zu der Lounge | reisetopia Basics
18006548818
Free Crossword Puzzles | BestCrosswords.com
Lesly Center Tiraj Rapid
9294027542
O'reilly's On Marbach
2000 Fortnite Symbols
Where Is Darla-Jean Stanton Now
Hcs Smartfind
Turning Obsidian into My Perfect Writing App – The Sweet Setup
ats: MODIFIED PETERBILT 389 [1.31.X] v update auf 1.48 Trucks Mod für American Truck Simulator
Latest Posts
Article information

Author: Laurine Ryan

Last Updated:

Views: 5256

Rating: 4.7 / 5 (77 voted)

Reviews: 84% of readers found this page helpful

Author information

Name: Laurine Ryan

Birthday: 1994-12-23

Address: Suite 751 871 Lissette Throughway, West Kittie, NH 41603

Phone: +2366831109631

Job: Sales Producer

Hobby: Creative writing, Motor sports, Do it yourself, Skateboarding, Coffee roasting, Calligraphy, Stand-up comedy

Introduction: My name is Laurine Ryan, I am a adorable, fair, graceful, spotless, gorgeous, homely, cooperative person who loves writing and wants to share my knowledge and understanding with you.