更聪明的json缩进器

jsview的Python项目详细描述


版权所有(c)2016-2018 Fabien Fleuto。

此软件在 MIT public license

(某种)智能json格式化程序。

我找到的每个json格式化程序都在每个 列出项和每个对象对。结果,不是 无法读取,因为它太大(在一行中),结果是 json不可读,因为太高(换行太多),特别是 当处理像geojson这样的格式时 坐标被处理。

默认情况下,此格式化程序使用80的页面宽度,并且 尝试在宽度和高度上优化屏幕空间的使用。

安装

pip install jsview

用法

jsview.py [-h] [-w WIDTH] [-i INDENT] [-o OUTPUT] [-l] [-u] [-r] filename

Format JSON inputs with smart line-returns and indendation.

positional arguments:
  filename              Input file; use '-' to read from stdin

optional arguments:
  -h, --help            show this help message and exit
  -w WIDTH, --width WIDTH
                        Set the ideal width of the output text; if unspecified,
                        try to fit the terminal's width as returned by stty.
  -i INDENT, --indent INDENT
                        Indentation, in number of space characters; default=2
  -o OUTPUT, --output OUTPUT
                        Output file; defaults to stdout
  -l, --close-on-same-line
                        When set, further lines are saved by closing lists and
                        objects on the same line as the last element.
  -u, --utf8-output     Output strings as UTF8 rather than ASCII 7 bits
  -r, --reformat        When set, file content is replaced by a reformatted
                        version. File must not be '-'.

示例

下面是将非平凡的json输入格式化为80个字符宽的结果:

{
  "crs": {"type": "name", "properties": {"name": "urn:ogc:def:crs:EPSG::4326"}},
  "totalFeatures": 116570,
  "type": "FeatureCollection",
  "features": [
    {
      "geometry": {
        "type": "Polygon",
        "coordinates": [
          [[-3.59, 48.28], [-3.57, 48.28], [-3.54, 48.28], [-3.53, 48.26],
            [-3.51, 48.25], [-3.49, 48.24], [-3.47, 48.22], [-3.48, 48.21],
            [-3.5, 48.2], [-3.5, 48.18], [-3.48, 48.17], [-3.49, 48.15],
            [-3.52, 48.15], [-3.53, 48.14], [-3.56, 48.14], [-3.58, 48.14],
            [-3.59, 48.15], [-3.58, 48.17], [-3.58, 48.19], [-3.57, 48.21],
            [-3.57, 48.23], [-3.58, 48.25], [-3.6, 48.26], [-3.59, 48.28],
            [-3.59, 48.28]]]
      },
      "properties": {
        "lastrevision": "2016-02-17T15:40:00Z",
        "probability": 0,
        "convectiontype": "ASPOC3D",
        "directiontowards": 90.06896,
        "top": 310,
        "phasetype": null,
        "convectioncelltopvariation": "CONSTANT",
        "intensity": "LIGHT",
        "base": 0,
        "identifier": "OPIC_RADAR.1.201602171540000060_310",
        "speed": 9.1,
        "obsorfcsttime": "2016-02-17T16:40:00Z"
      },
      "type": "Feature",
      "id": "convectionAirm.3449590",
      "geometry_name": "extent"
    }
  ]
}

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java 401在API URL上带有声明性Http客户端,并带有@Secured(SecurityRule.IS_ANONYMOUS)注释   java如何在Android中创建计时器?   Java8WebStart安全弹出窗口   java会通过以下两种方式导致堆空间耗尽吗?   java项目调度GA:染色体的高效数据结构   java Apache POI:如何在Excel文件中插入列   java在JRE系统库中每个jar扮演什么角色   java如何在抽象类中执行@mock(不是注入mock)   java如何使用opensearch和Lucene发送搜索查询?   java在ApachePOI中处理空列   java广播接收器未接收到目标   java错误ELF类:ELF类64(可能原因:体系结构字宽不匹配)   java调用Web服务(SSL)时出错   用于iot集线器设备固件更新的java Rest API   通过xslt将xml转换为文本文件时引发java异常   Java linux打印问题   Java XML转换器重复行   java从另一个类的方法将数组导入mainActivity类   多线程选择与Java交互的线程   我想在java程序中打印以下格式的文件: