如何美化文档中的 JSON?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1780048/
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:21:52  来源:igfitidea点击:

How can I beautify JSON inside a document?

jsonlatexcode-formatting

提问by Legend

I was writing a LaTeX document, using Lyx as a front-end. I did not find a way to correctly format JSON data inside these documents.

我正在编写 LaTeX 文档,使用 Lyx 作为前端。我没有找到在这些文档中正确格式化 JSON 数据的方法。

How can I beautify or format JSON data inside a Latex document?

如何美化或格式化 Latex 文档中的 JSON 数据?

采纳答案by Oliver Friedrich

I do embed code into lyx mostly as program listings imported from external textfiles. There are numerous options that you could apply to the program listing, from line numbers to word wraps and many more.

我确实将代码嵌入到 lyx 中,主要是作为从外部文本文件导入的程序列表。您可以将许多选项应用于程序列表,从行号到自动换行等等。

回答by Lukasz R.

I'm using mintedpackage.

我正在使用minted包。

First you have to install and configureit (do not forget to add pygmentize.cmdfile on Windows 7). Then you have to add \usepackage{minted}to the LaTeX Preambeland finally insert following code into TeX Codebox (for JSON you can use jscode type):

首先你必须安装和配置它(不要忘记在 Windows 7 上添加pygmentize.cmd文件)。然后,你必须添加\usepackage{minted}LaTeX Preambel最后插入下面的代码放入TeX Code盒(用于JSON,您可以使用js码型):

\begin{listing}
\begin{minted}[frame=single,
               framesep=3mm,
               linenos=true,
               xleftmargin=21pt,
               tabsize=4]{js}
{     
    "firstName": "John"
    "lastName" : "Smith",
    "age" : 25
}
\end{minted}
\caption{JSON example} 
\label{json-example}
\end{listing}

It is not perfect solution, but it works and produce really nice listing: minted json example

这不是完美的解决方案,但它可以工作并产生非常好的清单: 铸造 json 示例