Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure syntax highlighting in VSCode for JSONL — "JSON-Lines" — when the file type isn't supported

I am working with JSONL ("JSON Lines") files that implement the file extension, .jsonl, and therefore; I was wondering if there is a way to add support to V.S. Code for jsonl — (e.g "JSON-Lines") — when the file type isn't technically supported by the editor yet?

I was thinking that it might be possible to have support added to V.S. Code?

It is recommended here, that one should search for an extension that adds support to the editor for JSON Lines (.jsonl) files (per recommendation), however, to my dismay, no VSCode extensions existed, that add support for .jsonl files, at the time of authoring this question.

I also searched Marketplace for "JSON Lines" and ".jsonl", and once again, the search did not return any useful results.

like image 316
Max Heiber Avatar asked Mar 30 '21 16:03

Max Heiber


People also ask

Is json and Jsonl same?

A JSONL file is a JSON file created in the JSON Lines format. It contains plain text used to describe structured data. JSONL files are used primarily to stream structured data that should be processed one record at a time.

How do I change syntax highlighting in VS Code?

To change the text and syntax colors in visual studio code follow the steps given below: Open VS Code editor to change the syntax colors. Go to Settings, which is on the bottom left corner of the VS Code window. In the search field type JSON, and click on the 'Edit in settings.

How do you edit settings JSON file in VS Code?

You can open the settings. json file with the Preferences: Open Settings (JSON) command in the Command Palette (Ctrl+Shift+P). Once the file is open in an editor, delete everything between the two curly braces {} , save the file, and VS Code will go back to using the default values.


1 Answers


2021-JULY-21st @ 04:08 UTC —  EDIT: "Added another possible solution"

Possible Solution for Supporting Unsupported File-Types


While answering another question that was sort of about "language-support in V.S. Code", I remembered the question from this 'Q & A', and I realized that there was a solution that may have worked. If the author has not yet found a solution, then I suggest that they try this, and if someone else stumbles along this question looking to add support for an unsupported language.

First off, if the language, &/or file-type you are adding is completely unique then this solution will not work, furthermore; if you are able to gain support, it may not be full suport, or it may have other problems. Let me give you an example, as to help you fully understand what it is I am trying to tell you.

Example:


To start, let me show you the syntax for the solution. This is a setting used in V.S. Code's settings.json file — it can be placed in either the user's, or the workspace's implementation of the settings.json file.
   // "./.vscode/settings.json"

   "files.associations": {
       "json": "jsonc"
   },

"Hypothetically, lets say V.S. Code does not support the JSONC file type — 'JSON with Comments'. If the previous statement were true, which it isn't, but if it were, then this solution would work, however, if you have JSONC files already filled with data, then you will likely get errors, as the JSONC file type is used to implement comments in a JSON file, however, V.S. Code's JSON language does not support comments, and the editor will display errors for every comment that there is in a JSONC document, because when you configure your editor this way, V.S. code treats JSONC files as JSON files."



"There are other instances where using this configuration works better. Since we already used JSONC as an example, I'll give you a real world example, where the File-Associations Setting is used to support comments in .json (JSON) files — remember, the above was a hypothetical example, this one is an actual example practiced by developers."
"Adding comments to JSON file is simple, and quick, using the File Association Setting, simple invert the configuration from the code block above, so that the settings configuration looks like the example below. If you type the configuration into your .vscode/settings.json file, you will find that V.S. Code won't complain when you add a comment to a JSON file anymore.
    // "./.vscode/settings.json"  

    "files.associations": {
        "jsonc": "json"
    }, 
Basically, in a nutshell, you may, and you may not, be able to get some support, possibly limited support, or maybe full support, using the File Associations (file.associations) setting. It's easy to try, and it is much faster, and far less work, than to add support to V.S. Code for an entire programming language, or data file-type.

(EDITED: Dec 04th 2021)


I wanted to insert here that I have been taking a C++ class, and I use CLang-format-12 for my formatter. CLang-Format requires that users implement a .clang-format file in the project to customize the configuration of CLang-format (if your familiar with JS, it is the equivalent to an .eslintrc file for ESLint). Sometimes VS-Code auto detects the file as being in YAML format, which is accurate, however, sometimes it detects it as being python??? I don't write python, but something in the syntax seems python'ishy to the "VSCode Auto-detect file format feature", sometimes it detects it as MD, but it isn't in markdown format. It is in YAML format, but it technically is not a YAML document, however, using the file.associations setting I am able to accurately gain support for the file.

FYI, VSCode actually tries its best to add the support on its own, and detect what format a file is in, and what data-format/programming-language grammar, that it has access to, will work for the file your trying to use, but sometimes it needs some help. As I already stated, sometimes a file format will work, but the support might be limited, you will always need to tell VSCode what files types will work when support is limited.



2021-JUNE-23rd @ 22:45 UTC  —  ORIGINAL POST

Solutions for Supporting JSONL in V.S. Code


No one has created support for JSONL files in VSCode. Like you, I could not find an extension that adds language support for JSON Lines or JSONL files. The only way you will get support in VSCode, is if you add the support to VSCode. VSCode offers its users the tools they need to define a language. The tools they offer are the same tools that the MS VSCode development team uses to define language, in other words, the are good tools, and you can do cool stuff with them. This might not be worth considering if it was an entire language, but its not, its just a couple small additions to a preexisting data type. The hardest part will be reading the VSCode docs to learn how to use the Contributes property in the Extension Manifest, which is just a glorified package.json file.

I know that no-one likes to do extra work, especially if its more work than they have too, but I promise you that once you learn the basics of VSCode extension manifest & its contributes properties, plus a little bit about how TextMate works, you can do what you want to do in less than a few hours. Also the payoff is huge, learning how to make VSCode extensions is a decision I was really happy to make, I use the knowledge almost daily. Plus its the only way your gonna get support.



Here are a couple good places to start:


LANGUAGE DEFINITIONS (Official VSCode Website)
SYNTAX HIGHLIGHTING (Official VSCode Website)
CONTRIBUTES OBJECT (Official VSCode Website)
EXTENSION MANIFEST (Official VSCode Website)
TEXTMATE GRAMMARS DOCS (TextMate Official Website)
TEXTMATE TOKENS/SCOPES IN VSCODE (Official VSCode Website)



FINAL NOTE:

The only other option you have would be to email who ever it is that is in charge of JSON Lines, and ask them what editor they suggest using, or ask them if they plan on adding support to VSCode in the future.



like image 134
j D3V Avatar answered Nov 11 '22 05:11

j D3V