Jump to content

Pretty JSON


samuelraub

Recommended Posts

I'm the author

Github: https://github.com/samuelraub/pretty-json-alfred-workflow

 

From the About Page:

 

This workflow formats JSON.

 

Getting Started
Pretty JSON takes a JSON string from your clipboard, formats it and copies it back to your clipboard. Just copy some JSON and run it by typing `pj` in Alfred.screen_1.thumb.png.b7b95bc82e72a8fd6468a8540d561635.png

Advanced

  • You can set the default indent depth in the workflow configuration. Default is 2 spaces.
  • You can give `pj` a number as an argument to override the default indent depthscreen_3.thumb.png.92897dfd03c68818c76b686721f5ae2b.png
  • You can run pj as a text action
    screen_2.thumb.png.c2b71c61f5a31e2c596962920f44604d.png

Sample JSON for testing:

{"foo": 1, "bar": 2, "alfred": "cool"}
[{"foo": "bar"}, {"baz": 1}]

 

Edited by samuelraub
Link to comment
Share on other sites

Posted (edited)

Hey @vitor,

 

I've updated the workflow with the following changes:

image.thumb.png.590b82f7aa21312e2e12d0652e8be682.png

 

Maybe it would be nice to make `Post a Notification if input JSON is invalid` optional from the workflow config? Let me know what you think 🙂

Edited by samuelraub
add an idea
Link to comment
Share on other sites

2 hours ago, samuelraub said:

Maybe it would be nice to make `Post a Notification if input JSON is invalid` optional from the workflow config?

 

Doesn’t seem necessary. If the JSON is invalid it’s useful to know about it.

 

2 hours ago, samuelraub said:

Maybe it would be nice to expose an option in workflow config to anyway copy the input JSON, even if it's invalid.

 

Up to you. If the JSON is invalid, I’d say the clipboard should remain unchanged.

 

Found an issue, though. The Universal Action is working well, but the pj keyword isn’t. If I give it no argument it always returns that the JSON is invalid, and if I do give an argument (e.g. 4) it copies that number to the clipboard instead.

Link to comment
Share on other sites

23 hours ago, vitor said:

Found an issue, though. The Universal Action is working well, but the pj keyword isn’t. If I give it no argument it always returns that the JSON is invalid, and if I do give an argument (e.g. 4) it copies that number to the clipboard instead.

 

Of course. Fixed on `main`!

 

@vitor 

- I decided to still include the option to copy invalid, because users might fix the "invalidness" manually in an editor or something, yet disabled it by default in the workflow config

image.png.4bc87eb138e5b2b5101ce25e4fbc2291.png

Link to comment
Share on other sites

You should always fill the Checkbox Text to the right. That’s what screen readers speak to users. So something like Notification [x] Show error when JSON is invalid (probably won’t even need the description underneath). Same for the copy.

Link to comment
Share on other sites

Just now, samuelraub said:

Like so?

 

Looks good! Ideally the description text would start with an uppercase letter and end with a period (see Alfred’s own settings) but that’s not necessarily a problem for this initial version. I’ll take another full look shortly.

 

1 minute ago, samuelraub said:

Sorry to ping you everytime. LMK if that's inappropriate

 

It’s fine in this context. But it’s also unnecessary because I’ll get pinged anyway when you make a reply on the thread, regardless if you @vitor or not.

Link to comment
Share on other sites

In the process of adding it, found one extra thing. The bundle ID cannot start with com.alfredapp because a bundle ID is supposed to be the author’s domain. If you don’t have one, you can use app.alfred.samuelraub.prettyjson.


Also, as a tip: The pj subtitle should probably mention it will use the JSON in the clipboard, to add a bit of clarity for the user.

Link to comment
Share on other sites

On 6/24/2023 at 8:30 PM, vitor said:

n the process of adding it, found one extra thing. The bundle ID cannot start with com.alfredapp because a bundle ID is supposed to be the author’s domain. If you don’t have one, you can use app.alfred.samuelraub.prettyjson.

Would `de.samuelraub.prettyjson` work?

 

 

On 6/24/2023 at 8:30 PM, vitor said:

Also, as a tip: The pj subtitle should probably mention it will use the JSON in the clipboard, to add a bit of clarity for the user.

How about `Prettify the last clipboard item`?

 

Sorry. Was super busy the last couple of days.

Link to comment
Share on other sites

Just now, samuelraub said:

Would `de.samuelraub.prettyjson` work?

 

Yes, that’s even better.

 

1 minute ago, samuelraub said:

How about `Prettify the last clipboard item`?

 

Great too!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...