Skip to content
This repository

add json_encode for associative list to an object #52

Closed
wants to merge 1 commit into from

2 participants

Matthew Graham Bob Ippolito
Matthew Graham
mdg commented

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

Matthew Graham 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
Bob Ippolito
Owner

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

Bob Ippolito etrepum closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Jul 17, 2011
Matthew Graham 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
This page is out of date. Refresh to see the latest.

Showing 2 changed files with 4 additions and 0 deletions. Show diff stats Hide diff stats

  1. +2 0  src/mochijson.erl
  2. +2 0  src/mochijson2.erl
2  src/mochijson.erl
@@ -118,6 +118,8 @@ json_encode(F, _State) when is_float(F) ->
118 118 mochinum:digits(F);
119 119 json_encode(L, State) when is_list(L); is_binary(L); is_atom(L) ->
120 120 json_encode_string(L, State);
  121 +json_encode([{_K,_V}|_PropsT]=Props, State) ->
  122 + json_encode_proplist(Props, State);
121 123 json_encode({array, Props}, State) when is_list(Props) ->
122 124 json_encode_array(Props, State);
123 125 json_encode({struct, Props}, State) when is_list(Props) ->
2  src/mochijson2.erl
@@ -139,6 +139,8 @@ json_encode([{K, _}|_] = Props, State) when (K =/= struct andalso
139 139 json_encode_proplist(Props, State);
140 140 json_encode({struct, Props}, State) when is_list(Props) ->
141 141 json_encode_proplist(Props, State);
  142 +json_encode([{_K,_V}|_PropsT]=Props, State) ->
  143 + json_encode_proplist(Props, State);
142 144 json_encode(Array, State) when is_list(Array) ->
143 145 json_encode_array(Array, State);
144 146 json_encode({array, Array}, State) when is_list(Array) ->

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.