module JSON::OnSteroids::Searchable

Overview

Search a key (will be improved in next releases)

Direct including types

Defined in:

json_on_steroids/searchable.cr

Instance Method Summary

Instance Method Detail

def 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


[View source]
def dig?(key : String) : JSON::OnSteroids? #

[View source]
def 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 # => ""

[View source]