Parse Rates data into options label/value pairs (DEPREACTED)

Parse our rates data to Backbase options.json

by Amy L

HTML

<label for="input">Input rates data:</label>
<textarea id="input" rows="20" cols="100"></textarea>
<button onclick="parseData();">Parse</button>
<hr/>
<label for="output">Output:</label>
<div class="output">
	<textarea id="output" rows="20" cols="100"></textarea>
</div>


<script type="text/javascript">
var DATA = [
  {
	"id": "TFSAInvestmentSavings_2011_12_01_67452",
	"name": "TFSA Investment Savings",
	"effective_date": "2017-12-06",
	"products": [
	  {
		"id": "AllBalances_2011_12_01_80565",
		"name": "All Balances",
		"effective_date": "2017-12-06",
		"fixed_rate": 1.5,
		"variable_rate": 0.0,
		"buy_rate": 0.0,
		"sell_rate": 0.0,
		"term": 0,
		"include_in_calculators": false,
		"foreign_exchange_rate": false
	  }
	]
  },
  {
	"id": "VISA_2004_10_20_31322",
	"name": "FirstOntario Mastercard®",
	"effective_date": "2011-07-06",
	"products": [
	  {
		"id": "GoldVISA_2004_10_20_83694",
		"name": "Mastercard®",
		"effective_date": "2011-07-06",
		"fixed_rate": 19.49,
		"variable_rate": 0.0,
		"buy_rate": 0.0,
		"sell_rate": 0.0,
		"term": 0,
		"include_in_calculators": false,
		"foreign_exchange_rate": false
	  }
	]
  },
  {
	"id": "HeadStart_2011_06_29_20239",
	"name": "HeadStart® and FatCat® Savings",
	"effective_date": "2017-12-06",
	"products": [
	  {
		"id": "099999_2011_06_29_68782",
		"name": "$0 - $1000.00",
		"effective_date": "2017-12-06",
		"fixed_rate": 0.05,
		"variable_rate": 0.0,
		"buy_rate": 0.0,
		"sell_rate": 0.0,
		"term": 0,
		"include_in_calculators": false,
		"foreign_exchange_rate": false
	  },
	  {
		"id": "1000004_2011_06_29_29487",
		"name": "$1,000.01 - $5,000.00",
		"effective_date": "2017-12-06",
		"fixed_rate": 0.15,
		"variable_rate": 0.0,
		"buy_rate": 0.0,
		"sell_rate": 0.0,
		"term": 0,
		"include_in_calculators": false,
		"foreign_exchange_rate": false
	  },
	  {
		"id": "5000009_2011_06_29_97957",
		"name": "$5,000.01 - $10,000.00",
		"effective_date": "2017-12-06",
		"fixed_rate": 0.2,
		"variable_rate": 0.0,
		"buy_rate":...

JavaScript 1.7

function flattenData(data){
	let list = [];
	data.forEach((group) => {
		group.products.forEach((rate) => {
			list.push({
				label: group.name + ' - ' + rate.name,
				value: rate.id.toString()
			});
		});
	});
	return list;
}
function parseData() {
	const input = document.getElementById('input').value;
	const data = JSON.parse(input);
	var parsed = {
		options: {
			rateProduct: flattenData(data)
		}
	};
	var parsedStr = JSON.stringify(parsed);

	console.log(parsed);
	document.getElementById('output').value = parsedStr;
}