Skip to content
This repository
Browse code

fixing null and nil

  • Loading branch information...
commit 2a9a174e0bf7a34935b3de996071f47be2d56fac 1 parent 77624c6
Dickson S. Guedes authored
2  README.md
Source Rendered
@@ -57,7 +57,7 @@ This is a work-in-progress [JSON](http://www.ietf.org/rfc/rfc4627.txt) parser an
57 57 },
58 58 "tags": [ "test1", "test2", "test3" ]
59 59 }')
60   - #=> [ { "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" ] } ]
  60 + #=> [ { "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" ] } ]
61 61 ```
62 62
63 63 ## License
7 src/json_parser.erl
@@ -5,12 +5,13 @@ extract_value({_,_,Value}) -> Value.
5 5
6 6 build_object([L]) when is_list(L) -> L;
7 7 build_object(T) when is_tuple(T) -> [ T ];
8   -build_object(Any) -> lists:flatten(Any).
  8 +build_object(Any) -> Any.
9 9
10 10 build_pair(K, V) -> { list_to_binary(extract_value(K)), V }.
11 11
12 12 build_atom({_, _, A}) -> build_atom(A);
13 13 build_atom(A) when A == true; A == false ; A == nil -> A;
  14 +build_atom(null) -> nil;
14 15 build_atom(A) -> atom_to_binary(A, utf8).
15 16
16 17 -file("/usr/lib/erlang/lib/parsetools-2.0.7/include/yeccpre.hrl", 0).
@@ -197,7 +198,7 @@ yecctoken2string(Other) ->
197 198
198 199
199 200
200   --file("json_parser.erl", 200).
  201 +-file("json_parser.erl", 201).
201 202
202 203 yeccpars2(0=S, Cat, Ss, Stack, T, Ts, Tzr) ->
203 204 yeccpars2_0(S, Cat, Ss, Stack, T, Ts, Tzr);
@@ -560,4 +561,4 @@ yeccpars2_23_(__Stack0) ->
560 561 end | __Stack].
561 562
562 563
563   --file("json_parser.yrl", 79).
  564 +-file("json_parser.yrl", 80).
1  src/json_parser.yrl
@@ -75,4 +75,5 @@ build_pair(K, V) -> { list_to_binary(extract_value(K)), V }.
75 75
76 76 build_atom({_, _, A}) -> build_atom(A);
77 77 build_atom(A) when A == true; A == false ; A == nil -> A;
  78 +build_atom(null) -> nil;
78 79 build_atom(A) -> atom_to_binary(A, utf8).
2  test/json_parser_test.exs
@@ -68,7 +68,7 @@ defmodule JSON.Parser.ParseTest do
68 68 "inside_key": "a value",
69 69 "bool_value1": true,
70 70 "bool_value2": false,
71   - "nil_value": nil
  71 + "nil_value": null
72 72 },
73 73 "tags": [ "test1", "test2", "test3" ]
74 74 }')

0 comments on commit 2a9a174

Please sign in to comment.
Something went wrong with that request. Please try again.