I need Notepad++ to take a json string from this
{"menu": {"id": "file","value": "File","popup": {"menuitem": [{"value": "New", "onclick": "CreateNewDoc()"},{"value": "Open", "onclick": "OpenDoc()"},{"value": "Close", "onclick": "CloseDoc()"}]}}}
to this...
{"menu": {
"id": "file",
"value": "File",
"popup": {
"menuitem": [
{"value": "New", "onclick": "CreateNewDoc()"},
{"value": "Open", "onclick": "OpenDoc()"},
{"value": "Close", "onclick": "CloseDoc()"}
]
}
}}
I looked around at all the TextFX options but couldn't find anything that worked.
Update:
As of Notepad++ v7.6, use Plugin Admin to install JSTool per this answer
INSTALL
Download it from http://sourceforge.net/projects/jsminnpp/ and copy JSMinNpp.dll to plugin directory of Notepad++. Or you can just install "JSTool" from Plugin Manager in Notepad++.
New Notepad++ install and where did PluginManager go? See How to view Plugin Manager in Notepad++
{
"menu" : {
"id" : "file",
"value" : "File",
"popup" : {
"menuitem" : [{
"value" : "New",
"onclick" : "CreateNewDoc()"
}, {
"value" : "Open",
"onclick" : "OpenDoc()"
}, {
"value" : "Close",
"onclick" : "CloseDoc()"
}
]
}
}
}
Tip: Select the code you want to reformat, then Plugins | JSTool | JSFormat.
For Notepad++ v.7.6 and above Plugins Admin... is available.
Open Menu Plugins > Plugins Admin...
Search JSON Viewer
Check JSON Viewer in List
Click on Install Button
Restart Notepad++
Select JSON text
Go to Plugins > JSON Viewer > Format JSON ( Ctrl + Alt + Shift + M )
We can install any Notepad++ supported plugins using Plugins Admin...
You require a plugin to format JSON. To install the plugin do the following steps:
Open notepad++ -> ALT+P -> Plugin Manager -> Selcet JSON Viewer -> Click
Install
Restart notepad++
Now you can use shortcut to format json as CTRL + ALT +SHIFT + M
or ALT+P -> Plugin Manager -> JSON Viewer -> Format JSON
I personally use JSON Viewer since the Notepad++ plugin doesn't work any more.
EDIT - 24th May 2012
I advise that you download the JSMin plugin for Notepad as mentioned in the answer. This works well for me in the latest version (v6.1.2 at time of writing).
EDIT - 7th November 2017
As per #danday74's comment below, JSMin is now JSToolNpp. Also, please be aware that the JSON Viewer tool is on Codeplex which will likely disappear in the near future.
Given the above, this answer is no longer relevant and you should use Dan H's answer instead. My answer is simply here for posterity.
Universal Indent GUI plugin for Notepad++ will turn your sample into:
{
"menu" : {
"id" : "file", "value" : "File", "popup" : {
"menuitem" : [ {
"value" : "New", "onclick" : "CreateNewDoc()";
}
, {
"value" : "Open", "onclick" : "OpenDoc()";
}
, {
"value" : "Close", "onclick" : "CloseDoc()";
}
];
}
}
}
As per the latest notepad++, updated answer. Install JSON Viewer
Open notepad++ go to Plugins --> click Plugins Admin..
In Plugins Admin window search for JSON Viewer and click on Install
New after installing plugin, this is how you can view file in JSON format
simply go to this link
download the dll
copy and paste the dll to the plugins folder at notepad++, \Notepad++\plugins
restart the notepad++, and it should be shown in the list
NOTE: this dll supports 64 bit notepade++
Steps to add JSON viewer plugin for notepad++:
Download JSON viewer plugin for notepad++ from sourceforge.
Copy NPPJSONViewer.dll into Notepad++\plugins\NPPJSONViewer folder
restart the notepad++
select JSON and click on plugins > JSON Viewer > Format JSON (CTRL+ALT+SHIFT+M).
Done.
It's not an NPP solution, but in a pinch, you can use this online JSON Formatter and then just paste the formatted text into NPP and then select Javascript as the language.
If formatting JSON is the main goal and you have VisualStudio then it is simple and easy.
Open Visual Studio
File -> New -> File
Select Web in left side panel
Select JSON
Copy paste your raw JSON value
Press Ctrl + K and Ctrl + D
That's it. you will get formatted JSON Value.
JSMinNpp plugin will do this job.
https://sourceforge.net/projects/jsminnpp/
The following Notepad++ plugin worked for me as suggested by "SUN"
https://sourceforge.net/projects/jsminnpp/
You can view in Notepad++ no problem now (maybe older versions were bugged?)
for win64:
You can find the latest plugin here: https://github.com/kapilratnani/JSON-Viewer/releases . The latest zip file contains a .dll file.
And then follow the github priject README instructions:
Paste the file "NPPJSONViewer.dll" to Notepad++ plugin folder
open a document containing a JSON string
Select JSON fragment and navigate to plugins/JSON Viewer/show JSON Viewer or press "Ctrl+Alt+Shift+J"
Voila!! if the JSON is valid, it will be shown in a Treeview
It should be the same process for win32 but I cannot personally verify it.
If you don't want to install a Notepad++ plugin but you have Firefox and a JSON plugin for Firefox, you can select Run -> Launch in Firefox. You get the contents formatted as JSON using your Firefox plugin.
This is what I personally do.
It worked for me in the latest edition to Notepad using the UniversalIndentGui.
What I did was under the plugin setting choose Enable Text Auto Update, a window popped up and I selected javascript.
Notepad 5.8.7 and jsmin 1.7.0.0 works wonderful here.
Be careful though, found out jsmin eats the comments the hard way (should have read first).
I'm using the JSON Viewer plug-in with NPP 5.9 and it seems to work well.
I know this thread is old but I recently ran into a problem with JSToolNPP not being compatible with my newly updated N++, I did find a replacement that seems to work. http://sourceforge.net/projects/nppjsonviewer/
Use at your own risk, ofc. (standard disclaimer from me when linking anything outside the SExchange, fyi)
For those of us behind a corporate firewall with no direct access to the internet, using the Plugins Admin won't work. To use the JSMinNpp plugin, you can't just "copy the dll to the plugins folder". It needs to live inside a folder called "JSMinNpp" inside the plugins folder. After doing that and restarting Notepad++, I was able to see the "JSTool" menu option under the Plugins menu.
Tested with Notepad++ 7.8.2 and 7.8.9.
I use 32-bit Notepad++ version 7.5.6. I have found that 32-bit JSToolNpp 1.20.0
does a great job.
The direct link is:
https://sourceforge.net/projects/jsminnpp/files/Uni/JSToolNPP.1.2006.0.uni.32.zip/download
which is redirected from https://sourceforge.net/projects/jsminnpp/.
VirusTotal link:
https://www.virustotal.com/gui/file/008ee0ce889dfd9e96b975cebe6faafe28bc350352e951f3dec97e8e5bec5a07
JSON-Viewer
works fine too, but cannot sort the JSON data.
You can use http://www.jsonlint.com/ to edit your json online if you don't have Notepad++.
Your best bet is to use one of the latest versions of Eclipse (I am using Eclipse Galileo J2EE and Eclipse Ganymede J2EE). Create a JavaScript file, then create a variable:
var jsonObject = {"menu": {"id": "file","value": "File","popup": {"menuitem": [{"value": "New", "onclick": "CreateNewDoc()"},{"value": "Open", "onclick": "OpenDoc()"},{"value": "Close", "onclick": "CloseDoc()"}]}}};
Lastly, hit CTRL+SHIFT+F and voila! You have a nicely indented JSON Object. I, too, am looking for a Notepad++ JSON formatter, and I very well may be forced to develop an Npp plugin some short time in the future.
I know you asked about NotePad++ but TextMate for OS X can do it via the JSON bundle, its called the "Reformat Document" command.
Related
This is the code I have:
import pygame
pygame.init()
I'm very confused because if I try to run the file, then there seems to be no issue, but pylint says the following:
E1101:Module 'pygame' has no 'init' member
I have searched thoroughly for a solution to this "error". In every relevant case I found, the solution was to make sure that I have not made another file or folder with the name "pygame", because in that case, I would just be importing my own file or folder.
However, I have not made a folder or file with a name even close to "pygame", so I don't know what the problem is.
As said earlier, it seems like I'm able to run the file without any issues and having errors like this confuses me in my learning process.
I write code in Visual Studio Code, I'm using python 3.6, I'm using pygame 1.9.3 and have updated my pylint. Any help would be appreciated.
Summarizing all answers.
This is a security measure to not load non-default C extensions.
You can white-list specific extension(s).
Open user settings and add the following between {}:
"python.linting.pylintArgs": [
"--extension-pkg-whitelist=extensionname" // comma separated
]
You can allow to "unsafe load" all extensions.
Open user settings and add the following between {}:
"python.linting.pylintArgs": [
"--unsafe-load-any-extension=y"
]
If you have VS code, go in your .vscode folder > settings.json or search for python.linting.mypyArgs Under user settings tab paste inbetween curly braces
"python.linting.pylintArgs": [
"--extension-pkg-whitelist=lxml" // The extension is "lxml" not "1xml"
]
I no longer see the pyinit error.
I had the same issue when I started using Visual Studio Code with Python. It has nothing to do with having another pygame.py or not installing it properly. It has to do with the fact that Visual Studio Code takes your code literally, and since you cannot import pygame.init(), it thinks that it isn't a correct module.
To fix this, open up settings.json (go into your settings, and click the {} icon) and paste
"python.linting.pylintArgs": [
"--extension-pkg-whitelist=pygame"
]
to it.
I had the same issue with one of my modules. This is what I did to resolve the problem. (I'm using visual studio on windows 10)
Press CTRL+SHIFT+P in visual studio
Choose "Preferences: Open Settings (JSON)"
Add "python.linting.pylintArgs": ["--generate-members"] below one of the lines (put a comma if necessary)
Save the .json file (CTRL+S)
For me, the code looks like this :
{
"breadcrumbs.enabled": false,
"editor.minimap.enabled": false,
"python.pythonPath": "C:\\Users\\xxx\\Anaconda3",
"terminal.integrated.rendererType": "dom",
"window.menuBarVisibility": "default",
"workbench.activityBar.visible": false,
"workbench.statusBar.visible": true,
"python.linting.pylintArgs": ["--generate-members"], //line to add
"[json]": {
}
}
Hope it helps.
Credit to #Alamnoor on github
This answer includes the answer to your question. In short it explains:
Pylint imports modules to effectively identify valid methods and attributes. It was decided that importing c extensions that are not part of the python stdlib is a security risk and could introduce malicious code.
and as a solution it mentions, among others:
Disable safety using the .pylintrc setting unsafe-load-any-extensions=yes.
See here for more information about pylint.rc. Quickest method is to just create the file .pylintrc in your project directory or your home directory.
I found adding this in settings.json() solves the problem.
"python.linting.pylintArgs":[
"--extension-pkg-whitelist=pygame",
"--erros-only"
]
I find an answer and it really works for me.
See the accepted answer and change it to extension-pkg-whitelist=lxml
pylint 1.4 reports E1101(no-member) on all C extensions
I recommend going to the view tab, clicking command palette and searching preferences: open settings.json. Then add a comma on the last line of code.Below that paste this:
"python.linting.pylintArgs": [
"--extension-pkg-whitelist=extensionname" // comma separated
]
Then save your document (ctrl + s).
Check if you have a python file named pygame.py created by you in your directory. If you do, then the import pygame line is importing your own file instead of the real Pygame module. Since you don't have an init() function in that file, you're seeing this particular error message.
I found a solution, modifying the most voted answer:
"python.linting.pylintArgs": [
"--extension-pkg-whitelist=pygame"
]
Replaced the "lxml" with "pygame".
Disable Pylint
1.Press ctrl + shift + p
2.Then type Disable Pylint
If you are using vscode then you can go to settings:
python.linting.pylintEnabled = False
It will fix the problem. If you aren't using vscode then you can go the command prompt and manually uninstall pylint with the command
pip uninstall pylint.
I am using Visual Studio Code 1.60.1.
In my project I use many files called project.json and have created my custom JSON schema for them.
When I specify my schema via $schema field directly in project.json everything works just fine.
But I want to use .vscode/settings.json file for that:
{
"json.schemas": [
{
"fileMatch": [
"data/projects/list/*/project.json"
],
"url": "./.vscode/schemas/project.json"
}
]
}
This works too BUT in this case it appears that VS Code is mixing two schemas for my file, which is showing in a tip when I hover the opening { in editor:
JSON schema for .NET Core project.json files
[My scheme name]
This results in mixing properties and messed up hints and autocomplition suggestions.
How can I disable VS Code default ".NET Core" schema for my files and leave only my schema?
Turns out I had C# official extension installed.
I disabled it and everything is working just fine!
The moral is: if something goes wrong, don't forget to check your extensions!
I press ⌥ + ⇧ + F in Visual Studio Code for macOS, the shortcut to Format Document, to format a file called foo.rb or foo.html.erb.
Instead of formatting the document it prints out this letter: Ï
How do I get it to format the document?
You can set format associations in VSCode, so .erb files would be treated like .html.
Go to File->Preferences->Settings->Click ... in top right corner->Open settings.json
Then add this piece of code to your settings.json
"files.associations": {
"*.html.erb": "html"
}
This is how I solved this problem. It will remove some of the code highlights but will autoformat HTML templates like an HTML document.
You're going to need all of these settings in VS Code's settings.json file:
"ruby.rubocop.onSave": true,
"editor.formatOnSaveTimeout": 5000,
"editor.formatOnSave": true,
"files.associations": {
"*.erb": "erb"
},
Save the settings file. Install the "ruby-rubocop" and "ERB Formatter/Beautify" extensions on VS Code. Follow the documentation on both of those extensions to install their gem dependencies. Restart VS Code.
Format-on-save functionality will only trigger if the file is actually saved (which only happens if you change the file). Saving a file that has no changes will not trigger format-on-save.
If you're using prettier to format your html/css/js files, it is worth trying prettier-erb-plugin. Just add to your .prettierrc:
"plugins": ["#prettier/plugin-ruby", "prettier-plugin-erb"]
Or install it with yarn:
yarn add -D prettier #prettier/plugin-ruby prettier-plugin-erb
And make sure that VSCode uses local version of prettier from node_modules (or, you probably can install these plugins globally as well). Prettier VSCode plugin usually declared itself as default formatter, but just in case, make sure that in your settings.json is NOT written something like:
"[erb]": {
"editor.defaultFormatter": "aliariff.vscode-erb-beautify"
},
You can use Rufo to format your Ruby code. It is an opinionated formatter (like Prettier is for JS, if you are familiar with it).
You can use the vscode-rufo extension to integrate it with VSCode.
Update the settings.json of Visual Studio code:
File -> Preferences -> Settings -> Extensions -> Scroll down and find "Edit in settings.json"
Or in these paths in your OS
Windows %APPDATA%\Code\User\settings.json
macOS $HOME/Library/Application Support/Code/User/settings.json
Linux $HOME/.config/Code/User/settings.json
From Visual Studio Code Ruby extension documentation they recommend to use as an initial configuration:
"ruby.useBundler": true, //run non-lint commands with bundle exec
"ruby.useLanguageServer": true, // use the internal language server (see below)
"ruby.lint": {
"rubocop": {
"useBundler": true // enable rubocop via bundler
},
"reek": {
"useBundler": true // enable reek via bundler
}
},
"ruby.format": "rubocop" // use rubocop for formatting
Look at the linting documentation too for further improvements. Plus as mentioned previously, you can add that .erb should be treated as .html:
"files.associations": {
"*.html.erb": "html"
}
If you have no code formatting
That is, when you hit shift + option + F to format your code, vscode says something like:
install a formatter by clicking on the 'Extensions' tab on the left hand side of vscode, searching for 'ERB Formatter/Beautify' (by Ali Ariff), and installing it.
Run gem install htmlbeautifier
Press shift + command + P and search for
Preferences: Open Settings (JSON)
It should open a file that has a your JSON settings in it; something like this:
{
"window.zoomLevel": 1,
"editor.inlineSuggest.enabled": true
}
Add this to the settings.json file you opened in the previous step
"files.associations": {
"*.html.erb": "erb"
}
Your finished file might look like this:
{
"window.zoomLevel": 1,
"editor.inlineSuggest.enabled": true,
"files.associations": {
"*.html.erb": "erb"
}
}
Close and reopen vscode and it should now let you format with shift + option + F
If you have no syntax highlighting for erb files
The extension called 'ruby' will solve that.
Click on the 'Extensions' tab on the right hand side of vscode.
type in ruby
Install the ruby extension by Peng Lv
You may need to restart vscode
All done!
Reference
More info in this video
Nowadays (March 2019) I think prettier with prettier-ruby are the best options: it can handle Ruby, ERB (as HTML), JS, and many many more.
prettier script.rb # will show you the formatted script
prettier --write script.rb # will overwrite the file with the formatted script
You can use the Prettier VS Code plugin to do that automatically: https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode
https://github.com/prettier/plugin-ruby
gem install htmlbeautifier
through the search functionality provided in the editor with Ctrl +Shift+ P (or Command + Shift + P on Mac), and then searching for format document.
I use the rubocop instead of rufo.
At the beginning, I used rufo. However, I met the issue
{
boo: {
a: 1,
b: 2,
c: 3
}
}
it always format it for me as
{
boo: {
a: 1,
b: 2,
c: 3,
},
}
add two ,, behind c: 3 and boo: {}. It is that makes my rubocop fail always.
As for, I use the rubocop in the project. Why not use it format my codes directly!
If you are interested, you can do as the following:
install the plugin VSCode ruby and then add the following snippets in the the settings.json
"ruby.format": "rubocop",
"ruby.intellisense": "rubyLocate",
"ruby.useBundler": true,
"ruby.lint": {
"rubocop": {
"useBundler": true
}
},
save it. It works~~(I wish you)
It is now possible to:
Install ruby-rubocop in VS Code
Go to File -> Preferences -> Settings
Search for Editor: Default Formatter and select "misogi.ruby-rubocop"
Go to File -> Preferences -> Keyboard Shortcuts
Search for Ruby: autocorrect by rubocop. There you have the shortcut to run rubocop in order to automatic format your ruby code following your rubocop settings.
You may also right click in your ruby file and you will find the "Format Document" option, which triggers "Ruby: autocorrect by rubocop" once ruby-rubocop is installed.
To format your ruby files, you don't need any extra plugin, you can just map some keys to do "editor.action.reindentLines"
If you use vscode-vim plugin, you can add this to your settings:
"vim.normalModeKeyBindingsNonRecursive": [
{
"before": ["=", "="],
"commands": ["editor.action.reindentlines"]
}
],
Then in normal vim mode, == will reformat your file.
(Running ST2 on Win7)
Just looking into ST2 as an ide for WebDev. I've introduced a few packages, but have got a bit lost in the configuration of them! I've a couple of problems.
Firstly I've got ST2 configured to open the browser on file save, but unfortunately it opens all files rather than just .html files. Ideally I'd like it to live refresh if the js is already in use, but in the worst case, just open .html files and ignore .js files
Secondly when it opens a .html file it opens it as a file rather than via SublimeServer which is running. I've followed this link and believe SublimeServer is running on the same port.
Here's the SublimeServer config:
{
"attempts": 5,
"autorun": true,
"interval": 500,
"mimetypes":
{
"": "application/octet-stream",
".c": "text/plain",
".h": "text/plain",
".py": "text/plain"
},
"port": 8000
}
and the proj config
{
"folders":
[
{
"path": "/E/Projects/MyProjects/My.Web/My.Web.App/My.Web.App.Designer"
}
],
"settings":
{
"sublime-view-in-browser":
{
"baseUrl": "http://localhost:8000/",
"basePath": "E:\\Projects\\MyProjects\\My.Web\\My.Web.App\\My.Web.App.Designer"
}
}
}
So where do I need to look in the config to modify this behaviour?
EDIT:
The packages I currently have installed are:
Bracket Highlighter
Browser Refresh
DocBlockr
Emmet
Git
Grunt
JSLint
Nodejs
Package Control
Side Bar
SublimeCodeIntel
SublimeLinter
View in Browser
Web Inspector
(and SublimeServer)
I pretty much got them all from Package Control.
As I newbie, I may need to pair some of these back.
Many thx IA
Simon
The Ctrl + Shift + F hotkey in Eclipse can format a file. It doesn't work for .json files. How to make it work?
You'll want to get the JSON Editor plugin if you don't already have it. You can find it here
The JSON Editor is a simple plugin for the Eclipse IDE that provides: - Color text highlighting - An Outline Tree view - JSON validation - Text formatting - Text folding for the JSON data format.
If the hot keys still don't work. Take a look under the menu as shown in the picture from their site here
Also, I see that there has been at least one issue with what looks to be the current versions formatting feature in the past.
From their discussion site:
rlespinola
2010-07-15 00:18:05 UTC
Using version 0.9.4, I do not see the option to "Format Text". Also, when I open a .json file, the outline view says "An outline is not available".
jdschulteis
2010-12-27 16:59:24 UTC
Using 0.9.4 on Helios, I also had "An outline is not available". I went to Window->Preferences->General->Editors->File Associations, selected '*.json' in the 'File types:' list, selected 'Json Editor' in the 'Associated editors:' list, and clicked 'Default'. I now get an outline, though it can be somewhat slow (6K line file).
Edit:
There are several ways to add a plugin. Eclipse recommends using the update manager.
Try help > software updates > find and install
You can look here for some alternative methods.
There are two options I figured out using Eclipse Luna (4.4.0).
Use a JSON Editor Plugin and define shortcuts
Download and install the JSON Editor Plugin from sourceforge manually or use the Eclipse marketplace (Help -> Eclipse marketplace) to find and install the plugin
Go to Window -> Preferences -> General -> Keys and filter for "format text".
Choose "Format Text" and set the "When:" value to "Editing Text" (sadly there is no explicit condition for JSON editing, but the format event for the JSON Editor is different to the other editors, so "Editing Text" will work aswell)
Set the "Binding:" to Ctrl + Shift + F
Use the Javascript Development Plugin with an ugly and anoying workaround
Get the plugin using Help -> Install New Software -> Work with: "http://download.eclipse.org/releases/luna" -> Programming Languages -> JavaScript Development Tools
Associate *.json files with the JavaScript Editor (Window -> Preferences -> General -> Editors -> File Associations)
You can now create files with "json" extension and edit them in Eclipse using the JavaScript Editor, but formatting with Ctrl + Shift + F will not work directly with the following unformatted example:
{"addressbook": {"name": "John Doe",
"address": {
"street": "5 Main Street", "city": "San Diego, CA", "zip": 91912
},
"phoneNumbers": [
"619 555-3452",
"664 555-4667"
]
}
}
The hack is to create a valid JavaScript variable from the object description like this:
var obj = {"addressbook": {"name": "John Doe",
"address": {
"street": "5 Main Street", "city": "San Diego, CA", "zip": 91912
},
"phoneNumbers": [
"619 555-3452",
"664 555-4667"
]
}
}
Using Ctrl + Shift + F will now work
In the end you will have to remove the "var obj =" hack to make the JSON file valid again
You could use the JavaScript editor that ships with Eclipse.