如何在 Notepad++ 中重新格式化 JSON?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1560464/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 17:20:29  来源:igfitidea点击:

How to reformat JSON in Notepad++?

jsonparsingnotepad++

提问by Donny V.

I need Notepad++ to take a json string from this

我需要 Notepad++ 从这里获取一个 json 字符串

{"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.

我环顾了所有 TextFX 选项,但找不到任何有用的东西。

回答by Dan H

Update:

As of Notepad++ v7.6, use Plugin Adminto install JSTool per this answer

更新:

从 Notepad++ v7.6 开始,使用Plugin Admin根据此答案安装 JSTool

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++.

http://sourceforge.net/projects/jsminnpp/下载并复制 JSMinNpp.dll 到 Notepad++ 的 plugin 目录。或者您可以从 Notepad++ 中的插件管理器安装“JSTool”。

New Notepad++ install and where did PluginManager go? See How to view Plugin Manager in Notepad++

新的 Notepad++ 安装和 PluginManager 去哪里了?请参阅如何在 Notepad++ 中查看插件管理器

{
  "menu" : {
    "id" : "file",
    "value" : "File",
    "popup" : {
      "menuitem" : [{
      "value" : "New",
          "onclick" : "CreateNewDoc()"
        }, {
          "value" : "Open",
          "onclick" : "OpenDoc()"
        }, {
          "value" : "Close",
          "onclick" : "CloseDoc()"
        }
      ]
    }
  }
}

enter image description hereTip: Select the code you want to reformat, then Plugins | JSTool | JSFormat.

在此处输入图片说明提示:选择要重新格式化的代码,然后选择 Plugins | JS工具| JS格式。

回答by Hardik Leuwa

For Notepad++ v.7.6 and above Plugins Admin...is available.

对于 Notepad++ v.7.6 及更高版本,Plugins Admin...可用。

  1. Open Menu Plugins > Plugins Admin...

  2. Search JSON Viewer

  3. Check JSON Viewer in List

  4. Click on InstallButton

  5. Restart Notepad++

  6. Select JSON text

  7. Go to Plugins > JSON Viewer > Format JSON ( Ctrl+ Alt+ Shift+ M)

  1. 打开菜单插件 > 插件管理...

  2. 搜索JSON 查看器

  3. 检查列表中的 JSON 查看器

  4. 点击安装按钮

  5. 重启记事本++

  6. 选择 JSON 文本

  7. 转至插件 > JSON 查看器 >格式 JSON ( Ctrl+ Alt+ Shift+ M)

We can install any Notepad++ supported plugins using Plugins Admin...

我们可以使用Plugins Admin安装任何 Notepad++ 支持的插件...

回答by Dan Atkinson

I personally use JSON Viewersince the Notepad++ plugin doesn't work any more.

我个人使用JSON Viewer,因为 Notepad++ 插件不再工作了。

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.

编辑 - 2012 年 5 月 24 日

我建议您下载答案中提到的记事本的 JSMin 插件。在最新版本(撰写本文时为 v6.1.2)中,这对我来说效果很好。

编辑 - 2017 年 11 月 7 日

根据下面@danday74 的评论, JSMin 现在是JSToolNpp。此外,请注意 JSON 查看器工具位于 Codeplex 上,它可能会在不久的将来消失。

Given the above, this answer is no longer relevant and you should use Dan H's answerinstead. My answer is simply here for posterity.

鉴于上述情况,这个答案不再是相关的,你应该使用丹轰的答案,而不是。我的答案只是为了后代。

回答by JRL

Universal Indent GUIplugin for Notepad++ will turn your sample into:

Notepad++ 的通用缩进 GUI插件会将您的示例变成:

{
    "menu" : {
        "id" : "file", "value" : "File", "popup" : {
            "menuitem" : [ {
                "value" : "New", "onclick" : "CreateNewDoc()";
            }
            , {
                "value" : "Open", "onclick" : "OpenDoc()";
            }
            , {
                "value" : "Close", "onclick" : "CloseDoc()";
            }
            ];
        }
    }
}

回答by DevMJ

You required plugin to format JSON.To install plugin do following step

您需要插件来格式化 JSON。要安装插件,请执行以下步骤

  1. Open notepad++ -> ALT+P -> Plugin Manager -> Selcet JSON Viewer -> Click Install
  2. Restart notepad++
  3. Now you can use shortcut to format json as CTRL + ALT +SHIFT + Mor ALT+P -> Plugin Manager -> JSON Viewer -> Format JSON
  1. 打开记事本++ -> ALT+P -> 插件管理器 -> Selcet JSON 查看器 -> 点击安装
  2. 重启记事本++
  3. 现在您可以使用快捷方式将 json 格式化为CTRL + ALT + SHIFT + M或 ALT+P -> 插件管理器 -> JSON 查看器 -> 格式化 JSON

enter image description here

在此处输入图片说明

回答by Millhouse

It's not an NPP solution, but in a pinch, you can use this online JSON Formatterand then just paste the formatted text into NPP and then select Javascript as the language.

这不是 NPP 解决方案,但在紧要关头,您可以使用此在线JSON Formatter,然后将格式化的文本粘贴到 NPP 中,然后选择 Javascript 作为语言。

回答by SUN

JSMinNpp plugin will do this job. https://sourceforge.net/projects/jsminnpp/

JSMinNpp 插件将完成这项工作。 https://sourceforge.net/projects/jsminnpp/

回答by ibr

simply go to this linkdownload the dll copy and paste the dll to the plugins folder at notepad++, \Notepad++\pluginsrestart the notepad++, and it should be shown in the list

只需转到此链接下载dll复制并将dll粘贴到记事本++的插件文件夹中,\Notepad++\plugins重新启动记事本++,它应该显示在列表中

jsformatter

js格式化程序

NOTE: this dll supports 64 bit notepade++

注意:此 dll 支持 64 位记事本++

回答by Siva

The following Notepad++ plugin worked for me as suggested by "SUN" https://sourceforge.net/projects/jsminnpp/

按照“SUN”的建议,以下 Notepad++ 插件对我有用 https://sourceforge.net/projects/jsminnpp/

回答by User0106

If formatting JSON is the main goal and you have VisualStudio then it is simple and easy.

如果格式化 JSON 是主要目标,并且您拥有 VisualStudio,那么它就简单易行。

  1. Open Visual Studio
  2. File -> New -> File
  3. Select Web in left side panel
  4. Select JSON
  5. Copy paste your raw JSON value
  6. Press Ctrl + K and Ctrl + D
  1. 打开 Visual Studio
  2. 文件 -> 新建 -> 文件
  3. 在左侧面板中选择 Web
  4. 选择 JSON
  5. 复制粘贴您的原始 JSON 值
  6. 按 Ctrl + K 和 Ctrl + D

That's it. you will get formatted JSON Value.

就是这样。您将获得格式化的 JSON 值。