【问题标题】:Compare Json Files in Beyond Compare在 Beyond Compare 中比较 Json 文件
【发布时间】:2020-03-30 02:52:23
【问题描述】:

如何比较两个缩小的 json 文件无法比较?是否有内置的 json 文件格式?我希望比较底层 json 对象的两个漂亮的打印表示。

【问题讨论】:

    标签: diff beyondcompare


    【解决方案1】:

    一位代表在this thread 中说:

    虽然还没有在包装盒中,但我们确实有一个 JSON 排序格式可供下载,可在我们的其他文件格式部分下载:

    带有Scooter Software Downloads的链接

    【讨论】:

      【解决方案2】:

      您可以通过定义一个新的文件格式转换规则来实现这种特殊的差异功能。本示例是在 Windows 操作系统中进行的。

      步骤 0: 创建一个 python 转换脚本来渲染格式化的 json。将以下 python 脚本保存在硬盘上的某个位置

      import json
      import sys
      
      sourceFile = sys.argv[1]
      targetFile = sys.argv[2]
      
      with open(sourceFile, 'r') as file_r:
          # Load json data
          data = json.load(file_r)
      
          # Write formatted json data
          with open(targetFile, 'w') as file_w:
              json.dump(data, file_w, indent=4)
      

      第 1 步:在 BeyondCompare 菜单中导航至:Tools-->File Formats...

      第 2 步: 通过单击 + 按钮并选择 Text Format 创建新的文件格式条目

      第 3 步: 在文件格式的掩码字段中输入 *.json,以及任何有助于您回忆文件格式用途的说明。

      第 4 步:定义文件格式的转换设置。选择转换选项卡并从下拉菜单中选择外部程序(unicode 文件名)。 在 Loading 字段中写入以下 shell 命令

      python C:\Source\jsonPrettyPrint.py "%s" "%t"
      

      第 5 步:按“保存”按钮,并可选择通过在“文件格式名称和掩码”表中右键单击文件格式来重命名文件格式。

      可以通过查看pythondocumentation来考虑json转储的进一步专业化,例如sort_keys=True

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2014-05-22
        • 1970-01-01
        • 1970-01-01
        • 2018-03-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多