比较Besond中的Json文件 [英] Compare Json Files in Beyond Compare
问题描述
我如何才能在无法比较的情况下比较两个缩小的json文件?json是否有内置文件格式?我正在寻找比较底层json对象的两个漂亮的打印表示形式.
How can I compare two minified json files in beyond compare? Is there a built in file format for json? I'm looking to compare two pretty print representations of the underlying json objects.
推荐答案
您可以通过在无法比较的情况下定义新的文件格式转换规则来实现此专门的diff功能.此示例在Windows操作系统中进行.
You can achieve this specialized diff functionality by defining a new file format conversion rule in beyond compare. This example was conducted in the Windows OS.
步骤0::创建python转换脚本以呈现格式的json.将以下python脚本保存在硬盘上的某个地方
Step 0: Create a python conversion script to render the formatted json. Save the following python script somewhere on your harddrive
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 ...
Step 1: Navigate in the BeyondCompare menu to: Tools-->File Formats...
步骤2:通过单击 +
按钮并选择文本格式
,创建新的文件格式条目
Step 2: Create new file format entry by clicking on the +
button and select Text Format
第3步:在文件格式的掩码"字段中输入 *.json
,并输入任何有助于您回忆起文件格式用途的描述.
Step 3: Enter *.json
into the file format's Mask field, and any description that will help you recall the file format's purpose.
步骤4::定义文件格式的转换设置.选择转换选项卡,然后从下拉菜单中选择外部程序(unicode文件名).在加载"字段中,输入以下shell命令
Step 4: Define the file format's conversion settings. Select the Conversion tab and select External program (unicode filenames) from the pull down. In the Loading field write the following shell command
python C:\Source\jsonPrettyPrint.py "%s" "%t"
第5步:按下保存"按钮,然后选择右键单击文件格式名称和掩码"表中的文件格式来重命名文件格式.
Step 5: Press the Save button and optionally rename the file format by right clicking it in the File Formats Name and Mask table.
可以通过查看python 文档,例如 sort_keys = True
Further specializations of the json dumping could be considered by looking at the python documentation, eg sort_keys=True
这篇关于比较Besond中的Json文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!