Skip to content

Add Path.from_json_object_key #15877

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions spec/std/json/serialization_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions src/json/from_json.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down