I am trying to enable intelli-sense when I am editing the settings.json of the Windows Terminal. When this file is open auto-complete mostly does not work. I can seemingly get some suggestions, but it definitely does not include everything in the schema. For example, If i go to add a new command, man listed in schema , like 'newTab' to do pop up as possible options, unlike in this video: https://www.youtube.com/watch?v=NfgAOxfv0QU
schema is "https://aka.ms/terminal-profiles-schema",
I see an "unable to resole schema. Click to Retry" error in the bottom tray of VSCode. I can click to retry but nothing happens.
the $schema property has a squiggle underneath it that says "Draft 2019-09 schemas are not fully supported"
my settings.json looks like this (the default i think)
{
"json.schemas": [
{
"fileMatch": [
"/myfile"
],
"url": "schemaURL"
}
],
"[json]": {
"editor.quickSuggestions": {
"strings": true
},
"editor.suggest.insertMode": "replace"
}
}
More specifically, I DO get suggestions from the schema here:
"profiles":
{
"list":
[
{
"guid": "{574e775e-4f2a-5b96-ac1e-a2962a402336}",
"hidden": false,
"name": "PowerShell",
"source": "Windows.Terminal.PowershellCore",
"colorScheme": "Campbell Powershell",
"padding": "8, 8, 8, 8" //suggestions work here
},
But NOT here:
"actions":
[
{"command": "xxx", "keys":"zzz"} // no completion suggestions here
]
In neither case do I see squigglies under properties that are not in the scheme (e.g. if I mistype padding above)
It appears you're facing a known issue which has been raised here https://github.com/microsoft/vscode/issues/98724. This issue is still open.
A duplicate issue contains a work around however, which may be worth trying - https://github.com/microsoft/terminal/issues/7683.
"https://github.com/microsoft/terminal/raw/e504bf21402bca34e45863370aad9fefd543c292/doc/cascadia/profiles.schema.json". That was the last version before the schema was upgraded to draft 2019-09. If you change the schema URL like that, I think it will avoid the Draft 2019-09 schemas are not yet fully supported warning in Visual Studio Code...
Further down a user reports the workaround was successful for them.
Consider voting the GitHub issue!
So i have this small json database with list of entries, i tried making a python program that adds new items to the entries list and then overwrites the contents, the thing is, it fills the first line with a bunch of spaces, making JSON file unreadable for python.
{"entries":[
]
}
import json
f=open('test.json',"r+")
data=json.load(f)
def addme(x):
data["entries"].append({x:{
"added":True
}})
addme("jason")
f.truncate(0)
json.dump(data,f, indent=1)
f.close()
I expected it to look something like
{
"entries": [
{
"jason": {
"added": true
}
}
]
}
instead i got
{
"entries": [
{
"jason": {
"added": true
}
}
]
}
i tried removing indent parameter but that didn't work.
another interesting thing is that i cant copy paste contents of the file with spaces and spaces themselves.
Tried opening test.json in "r" mode, loading all data onto variable, closing the file and opening it again in "w+" mode seems to work for me.
I am completely unfamiliar with JSON. I don't use it on a regular basis so I'm just looking for a quick fix, but as a programmer I'd love some basic understanding also.
I'm using Brackets to edit some content for work, and auto-complete is driving me CRAZY. I hate you auto-complete, I hate you so much. I found a snippet of code at https://github.com/talmand/Brackets-Disable-AutoClose-Tags which is supposed to negate auto-complete when opening a new tag. It does not totally shut off auto-complete - it still tries to complete your closing tag once begun. Intended to be useful but I find it intensely irritating.
I inserted the code into the Preferences File, and in the statement, it seems pretty obvious that all I should need to do is change whenClosing to false, but when I do it, then close and reopen the program so it'll take effect, it tells me that my Preferences File contains invalid JSON. All I changed was the value true to false for whenClosing. I used JSONlint to try and see what's wrong, but JSON is not a familiar language for me. Code is included below.
What am I doing wrong?
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
This is the unaltered code that I copied into the file:
"closeTags": { "whenOpening": false, "whenClosing": true, "indentTags": [] }
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
And this is the total block that my Preferences File contains, with my edit:
{
"closeBrackets": false,
"debug.showErrorsInStatusBar": true
}
"closeTags": { "whenOpening": false, "whenClosing": false, "indentTags": [] }
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
And this is what JSONlint said:
Parse error on line 4:
...InStatusBar": true}"closeTags": { "
----------------------^
Expecting 'EOF', '}', ',', ']'
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#Shaunak that makes sense! I added the comma though, and got this:
You need a comma after closing bracket.
{
"closeBrackets": false,
"debug.showErrorsInStatusBar": true
}, <<<<<<<<< ----- You need a comma here :)
"closeTags": { "whenOpening": false, "whenClosing": false, "indentTags": [] }
JOSN object properties need to be saperated by a comma. Which is what the JSLint is telling you in that error.
UPDATE
Okay I suspected this, but thought you had only pasted partial code initially. Your preferences.json should actually look like this:
{
"closeBrackets": false,
"debug.showErrorsInStatusBar": true,
"closeTags": { "whenOpening": false, "whenClosing": false, "indentTags":[] }
}
So your problem was that, all preferences need to go in the main {} object. Without that main wrapping {} the JSON is invalid.
In future I recommend https://www.jsoneditoronline.org/ to validate and inspect your JSON strings.
[Update: 8 hours after this question was posted, the author of JSON bundle was notified of the issue and he fixed it.]
I have the following JSON data in a file application.json, shown at the end of this post, and I have used TextMate with the JSON bundle, Emacs, BBEdit, and Sublime Text 2 to properly indent it, but all seemed like they couldn't.
Both TextMate and Sublime Text 2 insisted that the first { should not be indented, and the first major issue was for the closing brace for "child": {. Both TextMate and Sublime Text 2 refused to align the } under the left side of "child": {. Emacs kept on indenting further and further for each line, and BBEdit didn't seem to have an re-indent function at all (could this be?).
Is there a way to properly indent the file, or are TextMate and Sublime Text 2 both doing the right thing for the JSON data?
[
{
"settings": [ "master" ],
"appPort": "8666",
"specs": {
"frame" : {
"type" : "HTMLFrameMojit",
"config": {
"deploy": true,
"child": {
"type" : "HelloWorldMojit"
},
"assets": {
"top": {
"css": [
"/static/HelloWorldMojit/assets/index.css"
]
}
}
}
}
}
},
{
"settings": [ "environment:development" ],
"staticHandling": {
"forceUpdate": true
}
}
]
EDIT: For BBEdit use siegel's suggestion of Text > Reformat Document
Original Reply:
I found a solution for BBEdit that is easy and works well.
Put the following script in
~/Library/Containers/BBEdit/Data/Library/Application Support/BBEdit/Text Filters/FormatJSON.sh (on MacOS 11 Big Sur, or above)
For MacOS 10.15 Catalina and below, use this location: ~/Library/Application Support/BBEdit/Text Filters/FormatJSON.sh
#!/bin/bash
python -m json.tool
Open a JSON file in BBEdit. There is no need to restart BBEdit because BBEdit rocks!
Select Text > Apply Text Filter > FormatJSON
I tested this with a JSON file that had 3,612,683 characters on a single line. BBEdit opened this file and reformatted without showing a "Spinning Beachball of Death" busy-wait mouse cursor.
Solution 1: Using Python
This answer is similar to this answer, except I am using python file to do the JSON format.
Exit bbedit application if it is open,
put following script pretty-json.py in ~/Library/Application\ Support/BBEdit/Text\ Filters/ path
#!/usr/bin/env python
# You can change above she-bang line depending on your Mac configuration
import sys
import json
def main():
input = sys.stdin.read()
try:
obj = json.loads(input)
except Exception as e:
print input + "\n\nERROR: " + str(e)
return 1
print(json.dumps(obj, indent=2))
return 0
if __name__ == '__main__':
sys.exit(main())
To Test, open a JSON file in BBEdit.
Select Text --> Apply Text Filter --> pretty-json.py
If you face any issue like formatting error, then the above script will add error in New file and will not change the original JSON.
which is not the case with this answer
Ref: https://gist.github.com/brokaw/95ade1358954cd97d0f2c8e992e14b08
For more info: Refer this
The above filter works fine for smaller JSON files, but if the JSON file is large(~ 40MB) then formatting will be slow.
To solve this, use the following solution
Solution 2: Using jq
For faster json formatting,
Install jq brew install jq
Check if you are able to execute jq in terminal, or need a full path, add whichever works in following file in place of jq
Add fast-json-pretty.sh file in ~/Library/Application\ Support/BBEdit/Text\ Filters/ location
Restart bbedit.
#!/bin/bash
jq
In BBEdit 14.0 and later, "Reformat Document" on the text menu will reflow JSON. You can also use the built-in Language Server Support with a JSON language server that supports reformatting.
I just corrected this issue in the bundle, for 2.0 users the bundle should update within 24 hours with the correction.
According to http://jsonprettyprint.com/ Textmate and Sublime aren't doing the right thing.
What version of Emacs did you use?
With 24.2.1, your JSON blob indented perfectly without issues in js-mode (Emac's default javascript major-mode).
If you do any significant Javascript development I recommend checkint out js2-mode https://github.com/mooz/js2-mode, which turns Emacs into a great JS IDE.
Sublime Pretty JSON
Sublime Pretty JSON indents the first { well.
This is what I get:
[
{
"settings": [
"master"
],
"appPort": "8666",
"specs": {
"frame": {
"type": "HTMLFrameMojit",
"config": {
"deploy": true,
"child": {
"type": "HelloWorldMojit"
},
"assets": {
"top": {
"css": [
"/static/HelloWorldMojit/assets/index.css"
]
}
}
}
}
}
},
{
"settings": [
"environment:development"
],
"staticHandling": {
"forceUpdate": true
}
}
]
Installation
Within Sublime Text 2: Preference => Package Control => Install Package => "Pretty Json" => Restart Sublime => Select JSON Text => Press:
Linux: ctrl+alt+j
Windows: ctrl+alt+j
OS X: cmd+ctrl+j
This is a solution simply using Google Chrome or NodeJS itself, and here is how:
Just open up the Google Chrome dev tool or NodeJS prompt, and type in
obj =
and copy and paste the object into it, so it will be like
obj = [
{
// etc
Now, in Google Chrome, just type
JSON.stringify(obj, null, 4)
and you will have the formatted JSON. In NodeJS, since it prints out the \n verbatim, you can use
console.log(JSON.stringify(obj, null, 4))
If you want the indentation to be just 2 spaces, just use 2 instead of 4.
If you want the indentation to be tabs instead of spaces, simply use
JSON.stringify(obj, null, "\t")
Create a script file fast-json-pretty.sh in ~/Library/Application\ Support/BBEdit/Text\ Filters/
Insert the following script:
#!/usr/bin/env bash
/usr/local/bin/jq .
Apply the text filter as follows: Menu bar --> Text --> Apply Text Filter --> fast-json-pretty
This is a reworked version of DKB's version of his JQ script as it, at least for me, required the full path and a dot (.) at the end to make this work.
Just check to see which version of python is installed:
using json_pretty will only work if the python interpreter is whatever is installed in the shell being called. For example, my json_pretty works and I have modded it as follows on Ventura:
#!/bin/zsh
python3 -m json.tool
I want to have a simple sublime-command to open a specific (dot config) file in my home folder. Is there a variable or other magic I can use like ${packages}, but for the user's home folder?
Currently I have (Default.sublime-commands)
{
"caption": "Edit my config",
"command": "open_file",
"args": {
"file": "/Users/MyName/.myconfig"
}
}
but want to get rid of the hard coded user name.
Unfortunately I can't find anything in the api "documentation" of sublime.
It can be done using custom command like this:
import sublime_plugin, getpass
class OpenCustomFileCommand(sublime_plugin.WindowCommand):
def run(self, file_name):
if("{username}" in file_name):
file_name = file_name.replace("{username}", getpass.getuser())
self.window.open_file(file_name)
and the following (Default.sublime-commands):
{
"caption": "Edit my config",
"command": "open_custom_file",
"args": { "file_name": "/Users/{username}/.myconfig" }
}
And of course you can extend OpenCustomFileCommand with your own replacements.
P.S. Command must be stored within Packages directory of ST2, i.e. in file open_custom_file.py