Insomnia Version: 5.7.4 (5.7.4.933)
If I write a js object, I want to format to a json (like jsoneditoronline), or when send it transform to json;
This is a fairly difficult problem to solve. Do you know of any existing libraries for converting JS syntax to JSON?
unsafe eval ?
That seems rather _unsafe_ 鈽狅笍
JSON.stringify().
@LouisRitchie it would need to be a JS object to do that. Hence the unsafe eval suggestion above to turn it from a string to a JS object.
Hmm, found a few suggestions here. https://stackoverflow.com/questions/9637517/parsing-relaxed-json-without-eval
Would JSON5 be acceptable? The project has been around for quite awhile and is based of Crockford's original implementation.
Edit: Derp, didn't see that stack answer recommends this :)
I think JSON5 could possibly work.
Do you think it would work better as it's own body type (ie. JSON & JSON5) or do we just patch JSON to try and parse, and if it fails fallback to JSON5?
I have not looked at the nunjucks templating code yet, but do you forsee any issues integrating with that?
Ya, I'm not quite sure about that yet. Currently, Insomnia uses a custom parser to prettify JSON in order to modify it as little as possible. It might actually be possible to modify it to do things like add quotes and ignore comments. It already does this with Nunjucks tokens.
Comments are actually pretty tricky though since you want to keep them in but you don't want to send them with the request. In that case, a new body type may be desirable.
Actually, this issue wasn't really about comments so maybe that doesn't matter.
There is actually already a way to do comments and that's using Nunjucks sytax {# a comment #}
Sure, thanks for the info! I think I will have some time this weekend to start hacking on this.
Awesome! What's your rough plan? Just want to make sure we're on the same page since a lot has been discussed here.
Also, let me know if there's anything I can help with. 馃榾
Hmm. I think the main scope of this and what I personally would like as well is just unquoted keys and single-quoted strings (trailing commas would be nice too).
Plan would be to see if we can just hack those into the existing parser and call it a win? As I said, have not looked at the code very closely at all (except to see that it is nicely organized 馃槃 ), so I think I will need to dig in/read a bit before I know more.
That sounds perfect. We were on the exact same page.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Most helpful comment
@LouisRitchie it would need to be a JS object to do that. Hence the unsafe eval suggestion above to turn it from a string to a JS object.