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

JSON <=> Javascript stringifier / parser #61

Open
jlarmstrongiv opened this issue Feb 6, 2021 · 5 comments
Open

JSON <=> Javascript stringifier / parser #61

jlarmstrongiv opened this issue Feb 6, 2021 · 5 comments
Labels

Comments

@jlarmstrongiv
Copy link

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
Copy link
Contributor

Hi there 👋

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

@jlarmstrongiv
Copy link
Author

jlarmstrongiv commented Feb 6, 2021

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
Copy link
Contributor

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
Copy link
Author

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
Copy link
Contributor

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

@trungdq88 trungdq88 added the ✋ Feature Request New feature label Feb 7, 2021
@trungdq88 trungdq88 changed the title JSON stringifier / parser JSON <=> Javascript stringifier / parser Feb 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants