Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Offer formatting option #135

Open
iwalucas opened this issue Apr 27, 2022 · 1 comment
Open

Offer formatting option #135

iwalucas opened this issue Apr 27, 2022 · 1 comment

Comments

@iwalucas
Copy link

I use meld a lot to compare JSON files, and its always an extra step for me to format that on some external tool, before pasting it into meld.
Any chance of adding some basic formatting options?

@robwijnhoven
Copy link

robwijnhoven commented Dec 11, 2023

Multiple people ran into this issue.
What I did to resolve it is to make a temp copy of each file which i "prettified" first, and then run meld.
Just place this in "/usr/local/bin/meldjson" and make it executable ($ chmod u+x /usr/local/bin/meldjson).
Note sure how safe this is, but it does the job!
Of course you could also create this script as a bash script...

#!/bin/bash
#Pretty meld: prettify JSON files and then execute meld.

script="
import json
import os

def clean(filename):
    filename_out = '/tmp/' + os.path.basename(filename)
    with open(filename) as f:
        data = json.load(f)
    with open(filename_out, 'w') as f:
        json.dump(data, f, indent=4, sort_keys=True)
    return filename_out
    
filename_tmp_1 = clean('$1')
filename_tmp_2 = clean('$2')
os.system('/usr/bin/meld ' + filename_tmp_1 + ' ' + filename_tmp_2)
os.system('rm ' + filename_tmp_1 + ' ' + filename_tmp_2)
"

python -c "$script"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants