Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fixing null and nil

  • Loading branch information...
commit 2a9a174e0bf7a34935b3de996071f47be2d56fac 1 parent 77624c6
@guedes authored
View
2  README.md
@@ -57,7 +57,7 @@ This is a work-in-progress [JSON](http://www.ietf.org/rfc/rfc4627.txt) parser an
},
"tags": [ "test1", "test2", "test3" ]
}')
- #=> [ { "key", "some value" }, { "another_key", [ "value1", "another value", "value 3" ] }, { "nested_key", [ { "inside_key", "a value" }, { "bool_value1", true }, { "bool_value2", false }, { "nil_value", nil } ] }, { "tags", [ "test1", "test2", "test3" ] } ]
+ #=> [ { "key", "some value" }, { "another_key", [ "value1", "another value", "value 3" ] }, { "nested_key", [ { "inside_key", "a value" }, { "bool_value1", true }, { "bool_value2", false }, { "nil_value", null } ] }, { "tags", [ "test1", "test2", "test3" ] } ]
```
## License
View
7 src/json_parser.erl
@@ -5,12 +5,13 @@ extract_value({_,_,Value}) -> Value.
build_object([L]) when is_list(L) -> L;
build_object(T) when is_tuple(T) -> [ T ];
-build_object(Any) -> lists:flatten(Any).
+build_object(Any) -> Any.
build_pair(K, V) -> { list_to_binary(extract_value(K)), V }.
build_atom({_, _, A}) -> build_atom(A);
build_atom(A) when A == true; A == false ; A == nil -> A;
+build_atom(null) -> nil;
build_atom(A) -> atom_to_binary(A, utf8).
-file("/usr/lib/erlang/lib/parsetools-2.0.7/include/yeccpre.hrl", 0).
@@ -197,7 +198,7 @@ yecctoken2string(Other) ->
--file("json_parser.erl", 200).
+-file("json_parser.erl", 201).
yeccpars2(0=S, Cat, Ss, Stack, T, Ts, Tzr) ->
yeccpars2_0(S, Cat, Ss, Stack, T, Ts, Tzr);
@@ -560,4 +561,4 @@ yeccpars2_23_(__Stack0) ->
end | __Stack].
--file("json_parser.yrl", 79).
+-file("json_parser.yrl", 80).
View
1  src/json_parser.yrl
@@ -75,4 +75,5 @@ build_pair(K, V) -> { list_to_binary(extract_value(K)), V }.
build_atom({_, _, A}) -> build_atom(A);
build_atom(A) when A == true; A == false ; A == nil -> A;
+build_atom(null) -> nil;
build_atom(A) -> atom_to_binary(A, utf8).
View
2  test/json_parser_test.exs
@@ -68,7 +68,7 @@ defmodule JSON.Parser.ParseTest do
"inside_key": "a value",
"bool_value1": true,
"bool_value2": false,
- "nil_value": nil
+ "nil_value": null
},
"tags": [ "test1", "test2", "test3" ]
}')
Please sign in to comment.
Something went wrong with that request. Please try again.