1 thought on “How do I create a modified version of an json from another website?”

  1. Done in pry:

    [15] pry(main)> require ‘json’
    => true
    [16] pry(main)> loaded = JSON.load(‘[ { “id”: “ethereum”, “name”: “Ethereum”, “symbol”: “ETH”, “rank”: “2”, “price_usd”: “47.0537”, “price_btc”: “0.0401068”, “24h_volume_usd”: “108034000.0”, “market_cap_usd”: “4268266618.0”, “available_supply”: “90710542.0”, “total_supply”: “90710542.0”, “percent_change_1h”: “-0.64”, “percent_change_24h”: “-6.51”, “percent_change_7d”: “11.72”, “last_updated”: “1492191264” } ]’)
    => [{“id”=>”ethereum”,
    “name”=>”Ethereum”,
    “symbol”=>”ETH”,
    “rank”=>”2”,
    “price_usd”=>”47.0537”,
    “price_btc”=>”0.0401068”,
    “24h_volume_usd”=>”108034000.0”,
    “market_cap_usd”=>”4268266618.0”,
    “available_supply”=>”90710542.0”,
    “total_supply”=>”90710542.0”,
    “percent_change_1h”=>”-0.64″,
    “percent_change_24h”=>”-6.51″,
    “percent_change_7d”=>”11.72”,
    “last_updated”=>”1492191264″}]
    [17] pry(main)> transformed = {
    [17] pry(main)* frames: loaded.map { |frame|
    [17] pry(main)* { icon: ‘i3219’, text: frame[‘price_usd’] }
    [17] pry(main)* }
    [17] pry(main)* }
    => {:frames=>[{:icon=>”i3219″, :text=>”47.0537”}]}
    [18] pry(main)> puts transformed.to_json
    {“frames”:[{“icon”:”i3219″,”text”:”47.0537″}]}

    Reply

Leave a Comment