diff --git a/spec/std/json/serialization_spec.cr b/spec/std/json/serialization_spec.cr index a3dad00a7737..cf6af88736b0 100644 --- a/spec/std/json/serialization_spec.cr +++ b/spec/std/json/serialization_spec.cr @@ -37,6 +37,10 @@ describe "JSON serialization" do Path.from_json(%("foo/bar")).should eq(Path.new("foo/bar")) end + it "does Path.from_json_object_key" do + Hash(Path, String).from_json(%({"foo/bar": "baz"})).should eq({Path.new("foo/bar") => "baz"}) + end + {% for int in BUILTIN_INTEGER_TYPES %} it "does {{ int }}.from_json" do {{ int }}.from_json("0").should(be_a({{ int }})).should eq(0) diff --git a/src/json/from_json.cr b/src/json/from_json.cr index 92edf0472c77..ef36b296ab66 100644 --- a/src/json/from_json.cr +++ b/src/json/from_json.cr @@ -199,6 +199,10 @@ def String.from_json_object_key?(key : String) : String key end +def Path.from_json_object_key?(key : String) : Path + new(key) +end + def Array.new(pull : JSON::PullParser) ary = new new(pull) do |element|