重点其实就是dumps函数的参数需要进行调节,一行代码

# json格式化输出
json.dumps(response.json(), sort_keys=True, indent=4, separators=(', ', ': '), ensure_ascii=False)


关于json的dump函数

直接去查看原函数,可以看到:

def dumps(obj, *, skipkeys=False, ensure_ascii=True, check_circular=True,allow_nan=True, cls=None, indent=None, separators=None,default=None, sort_keys=False, **kw):"""Serialize ``obj`` to a JSON formatted ``str``.If ``skipkeys`` is true then ``dict`` keys that are not basic types(``str``, ``int``, ``float``, ``bool``, ``None``) will be skippedinstead of raising a ``TypeError``.If ``ensure_ascii`` is false, then the return value can contain non-ASCIIcharacters if they appear in strings contained in ``obj``. Otherwise, allsuch characters are escaped in JSON strings.If ``check_circular`` is false, then the circular reference checkfor container types will be skipped and a circular reference willresult in an ``OverflowError`` (or worse).If ``allow_nan`` is false, then it will be a ``ValueError`` toserialize out of range ``float`` values (``nan``, ``inf``, ``-inf``) instrict compliance of the JSON specification, instead of using theJavaScript equivalents (``NaN``, ``Infinity``, ``-Infinity``).If ``indent`` is a non-negative integer, then JSON array elements andobject members will be pretty-printed with that indent level. An indentlevel of 0 will only insert newlines. ``None`` is the most compactrepresentation.If specified, ``separators`` should be an ``(item_separator, key_separator)``tuple.  The default is ``(', ', ': ')`` if *indent* is ``None`` and``(',', ': ')`` otherwise.  To get the most compact JSON representation,you should specify ``(',', ':')`` to eliminate whitespace.``default(obj)`` is a function that should return a serializable versionof obj or raise TypeError. The default simply raises TypeError.If *sort_keys* is true (default: ``False``), then the output ofdictionaries will be sorted by key.To use a custom ``JSONEncoder`` subclass (e.g. one that overrides the``.default()`` method to serialize additional types), specify it withthe ``cls`` kwarg; otherwise ``JSONEncoder`` is used."""

python格式化JSON结果打印相关推荐

  1. Python格式化JSON文件

    之前工作中有一个需求是要格式化json文件,遇到一个问题,是要把一个json文件里面的内容格式化一下,在此做个记录 import json class JsonFormat():     " ...

  2. python 格式化Json数据

    有2种方式处理Json数据,1是通过自带的json模块,通过json.loads和json.dumps方法进行处理.2是自己写模块处理json模块.本文讲的是第2种. 为什么要自己写模块调用呢,因为遇 ...

  3. python快速格式化json

    一.管道方式 echo '{"a": 1, "b": 2}' | python -m json.tool 二.文件方式 python -m json.tool ...

  4. python的format用法打印表格_Python格式化输出——format用法示例

    format OR % 提到Python中的格式化输出方法,一般来说有以下两种方式: print('hello %s' % 'world') # hello world print('hello {} ...

  5. python 格式化打印print常见用法(更新中)

    python 格式化打印print常见用法 1.一般打印 1.1打印到控制台 1.2 打印到文件 2.格式化打印 2.1 % 方法 2.1.1 格式化常用符号 2.1.2 格式化操作符辅助命令 2.2 ...

  6. 使用Python命令行优美打印json文件

    JSON 是一种非常常见的数据格式,但人工读起来比较困难.有的json文件就是非常长的一行文字,没有任何换行符和空格,对人来说,难以理解器内容. Python 2.6 及以上版本,提供了json.to ...

  7. linux 利用python模块实现格式化json

    非json格式示例 {"name": "chen2ha", "where": {"country": "Chi ...

  8. python -m json.tool 中文乱码 Format JSON with python

    python -m json.tool 中文乱码 Format JSON with python 现在以 json 为数据传输格式的 RESTful 接口非常流行.为调试这样的接口,一个常用的办法是使 ...

  9. python读取中文文件乱码-详解Python的json文件读取及中文乱码显示问题解决方法...

    Python的json文件读取及解决中文乱码显示问题 本文实例讲述了Python实现的json文件读取及中文乱码显示问题解决方法.分享给大家供大家参考,具体如下: city.json文件的内容如下: ...

  10. python simdjson_python+json

    JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式 一.json函数: 使用json函数需要导入json库:import json json.dumps()  ...

最新文章

  1. PCL调错(2):VTK报错
  2. 12c双机rac oracle_深度干货 | 如何借助云原生搞定Oracle备份快速恢复?
  3. 最小正连续子序列和 问题
  4. HTTP/3 未来可期?
  5. 计算机检索的pdf格式,win10系统实现全文搜索pdf文件的解决办法
  6. elementUI 分页组件Bug ,为什么会 infinity ?
  7. vb中SendMessage函数
  8. 修改密码-测试用例设计
  9. DispatcherServlet和Spring应用上下文初始化详解
  10. NTKO打开服务器上的文件
  11. vue项目引入阿里巴巴矢量图标库图标
  12. JS实现页面快捷键功能
  13. 计算机英语ppt答辩,急求英语答辩PPT范文
  14. FileZilla Server源码分析--大漠落日5节
  15. TB6612FNG模块使用说明
  16. composer的原理和正确使用(最新)
  17. 内部邮件管理的数据库设计和dwz的批量处理
  18. wpt eclipse 使用指南
  19. 辗转相除法和更相减损法原理和算法
  20. 可以动态控制左右滑动的ViewPager, 禁止ViewPager左右滑动

热门文章

  1. Linux中文输入法安装
  2. 【Java开发工具】Generator:Java代码生成工具
  3. 全球系留无人机系统行业调研及趋势分析报告
  4. python 通达信函数_python调用通达信公式,大智慧公式转python
  5. java贪吃蛇详细设计,javascript贪吃蛇游戏设计与实现
  6. 1、DSP28335 硬件概述与寄存器描述
  7. TI DSP28335学习路线分享
  8. 油猴脚本插件 千图网无水印原图素材
  9. html 音乐代码生成器,在线自动生成音乐播放器
  10. C语言关键字之inline