[erlang-questions] fast JSON parser in C
Ulf Wiger
ulf@REDACTED
Mon Jul 28 09:24:03 CEST 2008
2008/7/28 Richard A. O'Keefe <ok@REDACTED>:
> On 28 Jul 2008, at 10:48 am, Ulf Wiger wrote:
>>
>> But with dynamic code loading, you cannot be sure that the atoms
>> (presumably created when a given module is loaded) are there
>> when the message is decoded. If the message has been decoded
>> before a module matching on the decoded term is loaded, the
>> labels expected to be atoms may instead be binaries, and it would
>> be difficult to know which.
>
>
> That's easily dealt with:
>
> ensure_atoms_in_json(Term) ->
> json_to_term(term_to_json(Term),
> [{label,existing_atom}].
>
> This feature was never meant to be useful with things decoded
> before the module that cares was loaded. This really has nothing
> to do with JSON: it's an issue that comes up any time you make
> use of list_to_existing_atom/1.
True. For that reason, I tend to use list_to_existing atom/1 only
in order to assert that the atoms I try to create are atoms that
have already been statically created - since I have them declared
in the same module where i call on list_to_existing_atom/1.
BR,
Ulf W
More information about the erlang-questions
mailing list