module

JSON::OnSteroids::Searchable

Search a key (will be improved in next releases)

Instance methods

dig(key : String) : JSON::OnSteroids

Explore the json until a key is found.

  json.dig("a.b.c") # json["a"]["b"]["c"]

Integers in the dig path are working on both hash and arrays:

 json = JSON::OnSteroids.new(a: ["b", "c"])
 json.dig("a.0").as_s #return "b"

In case your key contains a dot ., you may want to escape it, using \:

  json.dig("a\\.b") #< equivalent to json["a.b"]

To mutate straight from dig, please check set method

dig?(key : String) : JSON::OnSteroids | Nil
path(arr = [] of String)

Return the current path of this mutable object. If the current object is the root object, return empty string.

 json["a"]["b"]["c"].path # => "a.b.c"
 json.path # => ""