DevUtilsApp / DevUtils-app

All-in-one Toolbox for Developers. Native macOS app.
https://devutils.com
Other
4.07k stars 218 forks source link

JSON <=> Javascript stringifier / parser #61

Open jlarmstrongiv opened 3 years ago

jlarmstrongiv commented 3 years ago

Often times, whether it’s debugging requests or setting up json configs, I kept wishing I had this little utility.

Related #48. But in addition to a parser, also a stringifier

trungdq88 commented 3 years ago

Hi there 👋

Can you elaborate on what would a "JSON stringifier" do or provide an example input/output? Thanks!

jlarmstrongiv commented 3 years ago

Sure

For example, I’m using a plugin called headwind that allows for custom regex configuration. I need to write the regex, and then stringify it.

Input:

(?:\b(?:class|className|tw)?\.?\w?\s*=*\s*{?[\"\'\`]([_a-zA-Z0-9\s\-\:/]+)[\"\'\`]}?)

Output:

(?:\\b(?:class|className|tw)?\\.?\\w?\\s*=*\\s*{?[\\\"\\'\\`]([_a-zA-Z0-9\\s\\-\\:/]+)[\\\"\\'\\`]}?)

I also stringify when debugging requests with postman or insomnia, as I send JSON payloads a lot.

The input can be a string, boolean, number, array, or object from JavaScript (as well as special types like undefined, null, regex, dates, and more too). I’ve been using tools like:

But it’d be great to have it in DevUtils 😄

trungdq88 commented 3 years ago

Ah I see, thanks for elaborating.

For stringifier, if I understand it correctly, it means you want to escape the reserved character in a JSON string, right?

Do you think the existing tool "Backslash Escape/Unescape" can do it? For example:

image

Can you test it out with a few cases and let me know if it gives the desired output? I'll consider updating the tool name/description to make it more friendly (maybe add a "stringifier" keyword to the description).

As for JSON Parser, the existing tool also allow you to see if there is any syntax error. Screenshot:

image

Is there a more specific case you are looking to use that the current JSON Format/Validate tool doesn't support?

jlarmstrongiv commented 3 years ago

Not quite, the main goal is converting the aforementioned JSON <=> Javascript. So both a stringifier and a parser.

The datatypes are normally objects and arrays, but also strings, booleans, numbers, null, and others.

The Backslash Escape/Unescape also doesn’t handle edge cases like converting undefined to null. It’s also soooooo much more convenient to just copy pasta my entire clipboard rather than find and convert specific lines with the Backslash Escape/Unescape tool (when working with requests, for example). Sure, the JSON Format/Validate tool will tell me that a JavaScript object is not JSON, but that’s not nearly as helpful as having a JavaScript to JSON converter actually convert it for me.

trungdq88 commented 3 years ago

I see. This is well noted :) Thanks for the suggestion!