Skip to content

Support function in {JSON:5} - #158

Closed
lifuzu wants to merge 1 commit into
json5:masterfrom
lifuzu:master
Closed

lifuzu wants to merge 1 commit into
json5:masterfrom
lifuzu:master

Conversation

@lifuzu

@lifuzu lifuzu commented Oct 23, 2017

Copy link
Copy Markdown

to support function as a value

@aseemk

aseemk commented Oct 23, 2017

Copy link
Copy Markdown
Member

Thanks for your first-time contribution, @lifuzu!

I'm personally pretty wary of supporting functions in JSON5, as they pretty firmly move us away from being a data format to now supporting arbitrary behaviors.

I know there are use cases, but I'd say for anything non-trivial, if you need functions, you might be better off just using JS directly rather than JSON5.

The other major problem with them is that they'll only work on JS runtimes. These days there are JSON5 parsers for other platforms too.

So I don't think we'll be able to merge this, but your thoughts/questions/etc. welcome!

@lifuzu

lifuzu commented Oct 24, 2017

Copy link
Copy Markdown
Author

@aseemk Thanks for the quick feedback. I totally understand what you are wary of.

Actually, the reason why I put function as a value into JSON is not to execute the code (yes, I will have another engine to take care of that part), just extract the code as a string. With this way we exactly use JSON as a data exchange carrier. In fact, without function we could use string to pass the function, but not human friendly.

For JS runtime problem, I think JS (function as the first class citizen, ref: http://ryanchristiani.com/functions-as-first-class-citizens-in-javascript/) is a great language for learning and using for all kinds of work. Some platforms have their JS interpreter (https://github.com/robertkrimen/otto, for go language). Besides, since function is not a mandatory, any other platforms could ignore if they don't want to have.

I am trying to combine the feature together with the best flavor of JSON I think so far. If it is not really fit for the initial design principle, I will have another repo to maintain the feature. And again I will continue to contribute something here once I have. :-)

@jordanbtucker

Copy link
Copy Markdown
Member

Hey, everyone. I'm going to close this issue because it is incompatible with the official specification. If you would like to continue this discussion, please open an issue on the official specification repository. Please see the new issues template for more information. Thanks.

@json5 json5 locked as off-topic and limited conversation to collaborators Aug 7, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants