Method: Faker::Json.add_depth_to_json
- Defined in:
- lib/faker/default/json.rb
.add_depth_to_json(json: shallow_json, width: 3, options: { key: 'Name.first_name', value: 'Name.first_name' }) ⇒ Hash{String => String}
Produces a random nested JSON formatted string that can take JSON as an additional argument.
71 72 73 74 75 76 77 78 79 80 |
# File 'lib/faker/default/json.rb', line 71 def add_depth_to_json(json: shallow_json, width: 3, options: { key: 'Name.first_name', value: 'Name.first_name' }) [:key] = "Faker::#{options[:key]}" [:value] = "Faker::#{options[:value]}" hash = JSON.parse(json) hash.each_key do |key| add_hash_to_bottom(hash, [key], width, ) end JSON.generate(hash) end |