Sha256: 46c37887e6f0794a7dee75df4e410aa6663895029dc9d55cf07268b66f0c491e

Contents?: true

Size: 514 Bytes

Versions: 26

Compression:

Stored size: 514 Bytes

Contents

#!/usr/bin/env ruby

require 'json'

data = STDIN.read

hash = JSON.parse(data)

def replace_value(value)
  if value.is_a?(String)
    return 'string'
  end
  if value.is_a?(Fixnum)
    return 1
  end
  if value.is_a?(Float)
    return 1.0
  end
  if value.is_a?(Array)
    return value.map! do |item|
      replace_value(item)
    end
  end
  if value.is_a?(Hash)
    return nest(value)
  end
end

def nest(hash)
  hash.each do |key, value|
    hash[key] = replace_value(value)
  end
end

puts nest(hash).to_json

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
ix-cli-0.0.27 bin/ix-json-replace-values
ix-cli-0.0.26 bin/ix-json-replace-values
ix-cli-0.0.25 bin/ix-json-replace-values
ix-cli-0.0.24 bin/ix-json-replace-values
ix-cli-0.0.23 bin/ix-json-replace-values
ix-cli-0.0.22 bin/ix-json-replace-values
ix-cli-0.0.21 bin/ix-json-replace-values
ix-cli-0.0.20 bin/ix-json-replace-values
ix-cli-0.0.19 bin/ix-json-replace-values
ix-cli-0.0.18 bin/ix-json-replace-values
ix-cli-0.0.17 bin/ix-json-replace-values
ix-cli-0.0.16 bin/ix-json-replace-values
ix-cli-0.0.15 bin/ix-json-replace-values
ix-cli-0.0.14 bin/ix-json-replace-values
ix-cli-0.0.13 bin/ix-json-replace-values
ix-cli-0.0.12 bin/ix-json-replace-values
ix-cli-0.0.11 bin/ix-json-replace-values
ix-cli-0.0.10 bin/ix-json-replace-values
ix-cli-0.0.9 bin/ix-json-replace-values
ix-cli-0.0.7 bin/ix-json-replace-values