[erlang-questions] erlang parser for javascript literals

63 views
Skip to first unread message

Joe Armstrong

unread,
Oct 8, 2012, 6:06:54 AM10/8/12
to Erlang
Does anybody have an Erlang parser for Javascript literals?

I have some JSON terms - I have to write them like this:

{"id" : 123,
"author" : "erl...@gmail.com",
"title" : "Some title",
"type" : "html",
"vsns":[{"vsn":1,
"time":"201200908113012",
"content":"<h1>This is html</h1>\n<pre>a\nb</pre>"}]
}

But I'd prefer to write them with far fewer quotes and with embedded
line feeds like this:

{id : 123,
author : "erl...@gmail.com",
title : "Some title",
type : html,
vsns:[{vsn:1,
time:"201200908113012",
content:"<h1>This is html</h1>
<pre>a
b
</pre>"}]
}

Or do any of the erlang JSON parsers handle non quoted names in object literals?


/Joe
_______________________________________________
erlang-questions mailing list
erlang-q...@erlang.org
http://erlang.org/mailman/listinfo/erlang-questions

dmitry kolesnikov

unread,
Oct 8, 2012, 6:41:41 AM10/8/12
to Joe Armstrong, Erlang
Hello Joe,

Object members without quotes is against JSON RFC. If you skip quotes
then this is not JSON any more.

I am using jsx parser, one of the best.
https://github.com/talentdeficit/jsx

Best Regards,
Dmitry >-|-|-*>

Jesper Louis Andersen

unread,
Oct 8, 2012, 7:21:55 AM10/8/12
to dmitry kolesnikov, Erlang
On Oct 8, 2012, at 12:41 PM, dmitry kolesnikov <dmkole...@gmail.com> wrote:

> Hello Joe,
>
> Object members without quotes is against JSON RFC. If you skip quotes
> then this is not JSON any more.
>

This is true, but it does not hold you back from choosing another representation format and then converting from that format into proper JSON later when you need to interact with other systems in a correct manner. Raw JSON is quite hard to write due to some of the rules in the dark corners of JS parsing :)


Jesper Louis Andersen
Erlang Solutions Ltd., Copenhagen

José Valim

unread,
Oct 8, 2012, 7:29:50 AM10/8/12
to Jesper Louis Andersen, Erlang
This is true, but it does not hold you back from choosing another representation format and then converting from that format into proper JSON later when you need to interact with other systems in a correct manner. Raw JSON is quite hard to write due to some of the rules in the dark corners of JS parsing :)

If you don't want to parse strictly JSON, YAML is an option that will give you more flexibility than JSON (and the features you asked).

There are some available Erlang wrappers for libyaml, but I haven't used them personally:


Eric Moritz

unread,
Oct 9, 2012, 9:11:22 AM10/9/12
to José Valim, Erlang
If you're writing out data structures by hand, YAML is the way to go.
Reply all
Reply to author
Forward
0 new messages