Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

add json_encode for associative list to an object #52

Closed
wants to merge 1 commit into from

2 participants

@mdg

lists of the type [{K,V},...] get encoded into a json object.
without this change, input of that structure just crashes.

it's a lot easier to get data into the associative list format than into the {struct, [{K,V}]} format

@mdg mdg add json_encode for associative list to an object
lists of the type [{K,V},...] get encoded into a json object.
without this change, input of that structure just crashes.
7c03a48
@etrepum
Owner

This doesn't work because it will break an array of {struct, _} for example.

@etrepum etrepum closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 17, 2011
  1. @mdg

    add json_encode for associative list to an object

    mdg authored
    lists of the type [{K,V},...] get encoded into a json object.
    without this change, input of that structure just crashes.
This page is out of date. Refresh to see the latest.
Showing with 4 additions and 0 deletions.
  1. +2 −0  src/mochijson.erl
  2. +2 −0  src/mochijson2.erl
View
2  src/mochijson.erl
@@ -118,6 +118,8 @@ json_encode(F, _State) when is_float(F) ->
mochinum:digits(F);
json_encode(L, State) when is_list(L); is_binary(L); is_atom(L) ->
json_encode_string(L, State);
+json_encode([{_K,_V}|_PropsT]=Props, State) ->
+ json_encode_proplist(Props, State);
json_encode({array, Props}, State) when is_list(Props) ->
json_encode_array(Props, State);
json_encode({struct, Props}, State) when is_list(Props) ->
View
2  src/mochijson2.erl
@@ -139,6 +139,8 @@ json_encode([{K, _}|_] = Props, State) when (K =/= struct andalso
json_encode_proplist(Props, State);
json_encode({struct, Props}, State) when is_list(Props) ->
json_encode_proplist(Props, State);
+json_encode([{_K,_V}|_PropsT]=Props, State) ->
+ json_encode_proplist(Props, State);
json_encode(Array, State) when is_list(Array) ->
json_encode_array(Array, State);
json_encode({array, Array}, State) when is_list(Array) ->
Something went wrong with that request. Please try again.