Open bbdevelopment opened 6 years ago
Baby can not infer all the Any?
type and data
which is a array with different type object in it.
You can modify the output struct as follow:
limit
, transform
, columnIndex
, collapse
and order
.MyData
enum to wrap the data
's object (It's a little bit complicated).Such as:
enum DecodingError: Error {
case typeMismatch
}
enum MyData: Codable {
case string(String)
case double(Double)
init(from decoder: Decoder) throws {
let container = try decoder.singleValueContainer()
if let x = try? container.decode(String.self) {
self = .string(x)
return
}
if let x = try? container.decode(Double.self) {
self = .double(x)
return
}
throw DecodingError.typeMismatch
}
func encode(to encoder: Encoder) throws {
var container = encoder.singleValueContainer()
switch self {
case .string(let x):
try container.encode(x)
case .double(let x):
try container.encode(x)
}
}
}
struct Aluminum: Codable {
struct Dataset: Codable {
let id: Int
let datasetCode: String
let databaseCode: String
let name: String
let description: String
let refreshedAt: Date
let newestAvailableDate: Date
let oldestAvailableDate: Date
let columnNames: [String]
let frequency: String
let type: String
let premium: Bool
let limit: Int?
let transform: Int?
let columnIndex: Int?
let startDate: Date
let endDate: Date
let data: [[MyData]]
let collapse: Int?
let order: Int?
let databaseId: Int
private enum CodingKeys: String, CodingKey {
case id
case datasetCode = "dataset_code"
case databaseCode = "database_code"
case name
case description
case refreshedAt = "refreshed_at"
case newestAvailableDate = "newest_available_date"
case oldestAvailableDate = "oldest_available_date"
case columnNames = "column_names"
case frequency
case type
case premium
case limit
case transform
case columnIndex = "column_index"
case startDate = "start_date"
case endDate = "end_date"
case data
case collapse
case order
case databaseId = "database_id"
}
}
let dataset: Dataset
}
Baby can not guarantee that it is always correct, but it can save your time to create the base struct.
I am getting the error that the struct does not conform to protocol encodable or decodable.
JSON String {"dataset":{"id":19704762,"dataset_code":"AB_AL","database_code":"LME","name":"Aluminium Asian Benchmark Prices","description":"LME Asian Benchmark Prices in US$ per tonne","refreshed_at":"2017-09-26T07:05:23.154Z","newest_available_date":"2017-09-25","oldest_available_date":"2015-02-11","column_names":["Date","Value"],"frequency":"daily","type":"Time Series","premium":false,"limit":null,"transform":null,"column_index":null,"start_date":"2015-02-11","end_date":"2017-09-25","data":[["2017-09-25",2141.67],["2017-09-22",2125.81],["2017-09-21",2160.63],["2017-09-20",2171.34],["2017-09-19",2101.15],["2017-09-18",2091.99],["2017-09-15",2090.37],["2017-09-14",2112.07],["2017-09-13",2133.04],["2017-09-12",2124.1],["2017-09-11",2126.71],["2017-09-08",2089.82],["2017-09-07",2090.77],["2017-09-06",2089.18],["2017-09-05",2110.8],["2017-09-04",2125.09],["2017-09-01",2139.74],["2017-08-31",2099.0],["2017-08-30",2101.03],["2017-08-29",2072.67],["2017-08-25",2110.29],["2017-08-24",2093.03],["2017-08-23",2069.82],["2017-08-22",2077.6],["2017-08-21",2081.47],["2017-08-18",2080.84],["2017-08-17",2109.43],["2017-08-16",2060.48],["2017-08-15",2035.97],["2017-08-14",2027.01],["2017-08-11",2035.98],["2017-08-10",2035.98],["2017-08-09",2035.98],["2017-08-08",1974.21],["2017-08-07",1924.33],["2017-08-04",1909.82],["2017-08-03",1920.5],["2017-08-02",1926.72],["2017-08-01",1913.12],["2017-07-31",1919.9],["2017-07-28",1936.36],["2017-07-27",1932.76],["2017-07-26",1943.34],["2017-07-25",1923.74],["2017-07-24",1920.46],["2017-07-21",1926.29],["2017-07-20",1924.4],["2017-07-19",1904.78],["2017-07-18",1904.78],["2017-07-17",1935.98],["2017-07-14",1928.5],["2017-07-13",1899.55],["2017-07-12",1899.84],["2017-07-11",1904.36],["2017-07-10",1921.68],["2017-07-07",1939.25],["2017-07-06",1929.09],["2017-07-05",1929.4],["2017-07-04",1924.41],["2017-07-03",1928.84],["2017-06-30",1913.36],["2017-06-29",1904.59],["2017-06-28",1890.93],["2017-06-27",1871.19],["2017-06-26",1874.45],["2017-06-23",1875.99],["2017-06-22",1868.64],["2017-06-21",1880.25],["2017-06-20",1899.69],["2017-06-19",1884.94],["2017-06-16",1874.42],["2017-06-15",1882.92],["2017-06-14",1890.37],["2017-06-13",1888.32],["2017-06-12",1899.98],["2017-06-09",1889.95],["2017-06-08",1915.22],["2017-06-07",1900.65],["2017-06-06",1897.7],["2017-06-05",1927.01],["2017-06-02",1930.62],["2017-06-01",1928.57],["2017-05-31",1915.56],["2017-05-30",1947.42],["2017-05-26",1963.93],["2017-05-25",1954.11],["2017-05-24",1935.67],["2017-05-23",1922.99],["2017-05-22",1936.54],["2017-05-19",1914.78],["2017-05-18",1906.34],["2017-05-17",1921.49],["2017-05-16",1902.27],["2017-05-15",1897.09],["2017-05-12",1880.79],["2017-05-11",1873.96],["2017-05-10",1868.59],["2017-05-09",1874.51],["2017-05-08",1890.17],["2017-05-05",1911.13],["2017-05-04",1913.4],["2017-05-03",1918.44],["2017-05-02",1905.14],["2017-04-28",1920.8],["2017-04-27",1965.42],["2017-04-26",1957.14],["2017-04-25",1950.17],["2017-04-24",1944.05],["2017-04-21",1953.76],["2017-04-20",1927.85],["2017-04-19",1903.92],["2017-04-18",1942.42],["2017-04-13",1915.0],["2017-04-12",1916.06],["2017-04-11",1919.67],["2017-04-10",1950.2],["2017-04-07",1947.25],["2017-04-06",1963.33],["2017-04-05",1961.08],["2017-04-04",1947.01],["2017-04-03",1970.47],["2017-03-31",1970.65],["2017-03-30",1956.79],["2017-03-29",1949.4],["2017-03-28",1923.51],["2017-03-27",1928.32],["2017-03-24",1927.1],["2017-03-23",1924.67],["2017-03-22",1925.91],["2017-03-21",1915.62],["2017-03-20",1906.33],["2017-03-17",1892.0],["2017-03-16",1901.13],["2017-03-15",1869.68],["2017-03-14",1869.55],["2017-03-13",1890.52],["2017-03-10",1885.2],["2017-03-09",1866.68],["2017-03-08",1877.28],["2017-03-07",1871.9],["2017-03-06",1876.33],["2017-03-03",1919.35],["2017-03-02",1937.62],["2017-03-01",1927.21],["2017-02-28",1895.09],["2017-02-27",1880.53],["2017-02-24",1870.68],["2017-02-23",1873.37],["2017-02-22",1871.81],["2017-02-21",1891.0],["2017-02-20",1889.16],["2017-02-17",1882.76],["2017-02-16",1903.22],["2017-02-15",1894.18],["2017-02-14",1894.32],["2017-02-13",1880.0],["2017-02-10",1849.85],["2017-02-09",1844.05],["2017-02-08",1836.4],["2017-02-07",1831.89],["2017-02-06",1824.26],["2017-02-03",1824.34],["2017-02-02",1823.25],["2017-02-01",1826.05],["2017-01-31",1804.5],["2017-01-30",1822.33],["2017-01-27",1822.83],["2017-01-26",1848.08],["2017-01-25",1871.44],["2017-01-24",1848.37],["2017-01-23",1854.5],["2017-01-20",1814.74],["2017-01-19",1815.48],["2017-01-18",1797.17],["2017-01-17",1778.1],["2017-01-16",1805.95],["2017-01-13",1789.41],["2017-01-12",1764.93],["2017-01-11",1753.03],["2017-01-10",1728.08],["2017-01-09",1711.79],["2017-01-06",1694.81],["2017-01-05",1695.79],["2017-01-04",1689.5],["2017-01-03",1701.0],["2016-12-30",1695.27],["2016-12-29",1705.61],["2016-12-28",1725.05],["2016-12-23",1718.62],["2016-12-22",1720.86],["2016-12-21",1724.37],["2016-12-20",1708.12],["2016-12-19",1710.57],["2016-12-16",1733.0],["2016-12-15",1743.0],["2016-12-14",1734.56],["2016-12-12",1755.4],["2016-12-09",1740.12],["2016-12-08",1716.36],["2016-12-07",1713.98],["2016-12-06",1720.12],["2016-12-05",1718.75],["2016-12-02",1717.0],["2016-12-01",1737.96],["2016-11-30",1711.6],["2016-11-29",1728.79],["2016-11-28",1778.31],["2016-11-25",1754.93],["2016-11-24",1777.0],["2016-11-23",1754.08],["2016-11-22",1733.2],["2016-11-21",1712.87],["2016-11-18",1689.5],["2016-11-17",1694.82],["2016-11-16",1716.98],["2016-11-15",1718.07],["2016-11-14",1768.01],["2016-11-11",1770.0],["2016-11-10",1759.97],["2016-11-09",1712.12],["2016-11-08",1723.0],["2016-11-07",1724.3],["2016-11-04",1720.29],["2016-11-03",1719.5],["2016-11-02",1700.0],["2016-11-01",1734.99],["2016-10-31",1715.56],["2016-10-28",1697.96],["2016-10-27",1675.23],["2016-10-26",1673.66],["2016-10-25",1659.24],["2016-10-24",1635.93],["2016-10-21",1621.5],["2016-10-20",1624.26],["2016-10-19",1631.96],["2016-10-18",1677.07],["2016-10-17",1669.31],["2016-10-14",1692.52],["2016-10-13",1679.33],["2016-10-12",1674.83],["2016-10-11",1691.94],["2016-10-10",1682.83],["2016-10-07",1677.99],["2016-10-06",1665.16],["2016-10-05",1664.11],["2016-10-04",1669.53],["2016-10-03",1676.51],["2016-09-30",1662.67],["2016-09-29",1665.16],["2016-09-28",1654.56],["2016-09-27",1660.38],["2016-09-26",1632.62],["2016-09-23",1646.26],["2016-09-22",1602.4],["2016-09-21",1577.09],["2016-09-20",1587.27],["2016-09-19",1573.48],["2016-09-16",1579.48],["2016-09-15",1591.82],["2016-09-14",1565.03],["2016-09-13",1570.24],["2016-09-12",1567.56],["2016-09-09",1588.42],["2016-09-08",1587.41],["2016-09-07",1591.35],["2016-09-06",1590.27],["2016-09-05",1591.92],["2016-09-02",1613.4],["2016-09-01",1621.67],["2016-08-31",1627.02],["2016-08-30",1637.03],["2016-08-26",1650.88],["2016-08-25",1649.59],["2016-08-24",1667.0],["2016-08-23",1667.15],["2016-08-22",1655.74],["2016-08-19",1683.11],["2016-08-18",1700.34],["2016-08-17",1687.11],["2016-08-16",1676.84],["2016-08-15",1652.41],["2016-08-12",1648.2],["2016-08-11",1646.31],["2016-08-10",1653.13],["2016-08-09",1636.05],["2016-08-08",1652.73],["2016-08-05",1636.33],["2016-08-04",1637.0],["2016-08-03",1617.77],["2016-08-02",1638.14],["2016-08-01",1651.35],["2016-07-29",1607.16],["2016-07-28",1601.87],["2016-07-27",1593.8],["2016-07-26",1607.77],["2016-07-25",1616.23],["2016-07-22",1601.29],["2016-07-21",1630.39],["2016-07-20",1644.12],["2016-07-19",1657.5],["2016-07-18",1661.06],["2016-07-15",1680.81],["2016-07-14",1681.7],["2016-07-13",1681.12],["2016-07-12",1652.06],["2016-07-11",1668.26],["2016-07-08",1649.11],["2016-07-07",1654.97],["2016-07-06",1658.17],["2016-07-05",1644.34],["2016-07-04",1665.27],["2016-07-01",1660.22],["2016-06-30",1634.63],["2016-06-29",1626.11],["2016-06-28",1609.0],["2016-06-27",1611.08],["2016-06-24",1600.48],["2016-06-23",1631.43],["2016-06-22",1634.84],["2016-06-21",1637.46],["2016-06-20",1620.89],["2016-06-17",1621.76],["2016-06-16",1611.83],["2016-06-15",1609.23],["2016-06-14",1596.78],["2016-06-13",1566.14],["2016-06-10",1577.86],["2016-06-09",1619.41],["2016-06-08",1573.71],["2016-06-07",1548.0],["2016-06-06",1542.29],["2016-06-03",1546.77],["2016-06-02",1573.53],["2016-06-01",1548.53],["2016-05-31",1550.74],["2016-05-27",1559.5],["2016-05-26",1554.64],["2016-05-25",1544.11],["2016-05-24",1546.16],["2016-05-23",1535.69],["2016-05-20",1554.36],["2016-05-19",1544.35],["2016-05-18",1536.63],["2016-05-17",1562.22],["2016-05-16",1544.68],["2016-05-13",1545.5],["2016-05-12",1570.2],["2016-05-11",1571.0],["2016-05-10",1559.96],["2016-05-09",1579.05],["2016-05-06",1607.44],["2016-05-05",1633.75],["2016-05-04",1630.32],["2016-05-03",1682.83],["2016-04-29",1665.5],["2016-04-28",1634.5],["2016-04-27",1635.97],["2016-04-26",1642.55],["2016-04-25",1653.01],["2016-04-22",1640.22],["2016-04-21",1632.61],["2016-04-20",1584.95],["2016-04-19",1575.17],["2016-04-18",1545.33],["2016-04-15",1554.32],["2016-04-14",1547.93],["2016-04-13",1535.25],["2016-04-12",1502.36],["2016-04-11",1512.17],["2016-04-08",1498.75],["2016-04-07",1513.65],["2016-04-06",1511.13],["2016-04-05",1536.65],["2016-04-04",1530.65],["2016-04-01",1527.13],["2016-03-31",1495.02],["2016-03-30",1491.48],["2016-03-29",1482.85],["2016-03-24",1486.0],["2016-03-23",1495.0],["2016-03-22",1513.5],["2016-03-21",1520.5],["2016-03-18",1537.7],["2016-03-17",1526.0],["2016-03-16",1520.0],["2016-03-15",1543.09],["2016-03-14",1561.12],["2016-03-11",1570.5],["2016-03-10",1573.08],["2016-03-09",1567.0],["2016-03-08",1592.5],["2016-03-07",1579.87],["2016-03-04",1587.0],["2016-03-03",1591.0],["2016-03-02",1586.0],["2016-03-01",1569.0],["2016-02-29",1569.0],["2016-02-26",1570.5],["2016-02-25",1566.0],["2016-02-24",1546.0],["2016-02-23",1577.07],["2016-02-22",1551.0],["2016-02-19",1531.5],["2016-02-18",1525.03],["2016-02-17",1520.5],["2016-02-16",1525.04],["2016-02-15",1520.32],["2016-02-12",1492.5],["2016-02-11",1493.23],["2016-02-10",1487.0],["2016-02-09",1510.5],["2016-02-08",1504.5],["2016-02-05",1531.5],["2016-02-04",1536.0],["2016-02-03",1509.56],["2016-02-02",1516.97],["2016-02-01",1513.0],["2016-01-29",1518.12],["2016-01-28",1516.56],["2016-01-27",1507.5],["2016-01-26",1476.5],["2016-01-25",1478.0],["2016-01-22",1481.93],["2016-01-21",1466.5],["2016-01-20",1474.09],["2016-01-19",1496.9],["2016-01-18",1474.5],["2016-01-15",1468.5],["2016-01-14",1466.5],["2016-01-13",1462.0],["2016-01-12",1454.8],["2016-01-11",1477.08],["2016-01-08",1475.49],["2016-01-07",1462.5],["2016-01-06",1465.0],["2016-01-05",1497.0],["2016-01-04",1465.0],["2015-12-31",1506.5],["2015-12-30",1529.5],["2015-12-29",1521.02],["2015-12-24",1539.25],["2015-12-23",1523.77],["2015-12-22",1513.85],["2015-12-21",1520.0],["2015-12-18",1485.0],["2015-12-17",1484.0],["2015-12-16",1477.0],["2015-12-15",1481.5],["2015-12-14",1489.29],["2015-12-11",1505.0],["2015-12-10",1480.2],["2015-12-09",1490.42],["2015-12-08",1488.5],["2015-12-07",1508.0],["2015-12-04",1483.0],["2015-12-03",1472.0],["2015-12-02",1467.15],["2015-12-01",1457.15],["2015-11-30",1456.5],["2015-11-27",1499.99],["2015-11-26",1482.45],["2015-11-25",1453.55],["2015-11-24",1457.24],["2015-11-23",1443.12],["2015-11-20",1470.96],["2015-11-19",1464.71],["2015-11-18",1474.5],["2015-11-17",1466.48],["2015-11-16",1476.94],["2015-11-13",1497.15],["2015-11-12",1519.0],["2015-11-11",1489.64],["2015-11-10",1499.48],["2015-11-09",1516.4],["2015-11-06",1506.0],["2015-11-05",1495.56],["2015-11-04",1509.43],["2015-11-03",1506.25],["2015-11-02",1477.5],["2015-10-30",1475.5],["2015-10-29",1473.0],["2015-10-28",1468.15],["2015-10-27",1489.98],["2015-10-26",1498.5],["2015-10-23",1497.39],["2015-10-22",1513.0],["2015-10-21",1522.9],["2015-10-20",1536.97],["2015-10-19",1555.53],["2015-10-16",1565.71],["2015-10-15",1591.0],["2015-10-14",1587.5],["2015-10-13",1586.1],["2015-10-12",1627.92],["2015-10-09",1606.74],["2015-10-08",1568.05],["2015-10-07",1566.0],["2015-10-06",1557.5],["2015-10-05",1568.96],["2015-10-02",1566.67],["2015-10-01",1583.42],["2015-09-30",1577.9],["2015-09-29",1543.31],["2015-09-28",1565.77],["2015-09-25",1580.41],["2015-09-24",1583.25],["2015-09-23",1583.72],["2015-09-22",1607.96],["2015-09-21",1614.5],["2015-09-18",1624.89],["2015-09-17",1628.47],["2015-09-16",1621.13],["2015-09-15",1602.42],["2015-09-14",1627.17],["2015-09-11",1641.0],["2015-09-10",1630.2],["2015-09-09",1645.48],["2015-09-08",1603.0],["2015-09-07",1619.97],["2015-09-04",1630.25],["2015-09-03",1607.1],["2015-09-02",1600.29],["2015-09-01",1586.01],["2015-08-28",1567.55],["2015-08-27",1550.51],["2015-08-26",1542.9],["2015-08-25",1530.07],["2015-08-24",1527.03],["2015-08-21",1563.5],["2015-08-20",1561.06],["2015-08-19",1554.17],["2015-08-18",1562.24],["2015-08-17",1578.68],["2015-08-14",1569.94],["2015-08-13",1590.66],["2015-08-12",1559.82],["2015-08-11",1588.04],["2015-08-10",1590.12],["2015-08-07",1586.7],["2015-08-06",1593.54],["2015-08-05",1615.5],["2015-08-04",1615.5],["2015-08-03",1608.3],["2015-07-31",1635.36],["2015-07-30",1657.54],["2015-07-29",1665.67],["2015-07-28",1650.27],["2015-07-27",1635.05],["2015-07-24",1633.78],["2015-07-23",1661.73],["2015-07-22",1656.96],["2015-07-21",1685.71],["2015-07-20",1696.99],["2015-07-17",1715.0],["2015-07-16",1720.56],["2015-07-15",1716.93],["2015-07-14",1702.87],["2015-07-13",1695.57],["2015-07-10",1695.08],["2015-07-09",1681.61],["2015-07-08",1640.29],["2015-07-07",1689.04],["2015-07-06",1695.08],["2015-07-03",1724.97],["2015-07-02",1729.05],["2015-07-01",1685.15],["2015-06-30",1688.36],["2015-06-29",1703.71],["2015-06-26",1724.13],["2015-06-25",1712.65],["2015-06-24",1733.0],["2015-06-23",1719.51],["2015-06-22",1693.84],["2015-06-19",1700.29],["2015-06-17",1700.74],["2015-06-16",1716.28],["2015-06-09",1750.64],["2015-06-08",1747.71],["2015-06-05",1737.17],["2015-06-03",1741.5],["2015-06-02",1764.56],["2015-06-01",1751.67],["2015-05-29",1779.15],["2015-05-28",1747.85],["2015-05-27",1757.04],["2015-05-26",1771.19],["2015-05-22",1773.67],["2015-05-21",1786.42],["2015-05-20",1791.93],["2015-05-19",1815.18],["2015-05-18",1859.99],["2015-05-15",1871.8],["2015-05-14",1893.62],["2015-05-13",1904.22],["2015-05-12",1877.26],["2015-05-07",1894.93],["2015-05-06",1968.9],["2015-05-05",1903.96],["2015-05-01",1929.95],["2015-04-30",1886.36],["2015-04-29",1872.04],["2015-04-28",1842.62],["2015-04-27",1828.09],["2015-04-24",1785.02],["2015-04-23",1794.25],["2015-04-22",1820.5],["2015-04-21",1811.3],["2015-04-20",1834.26],["2015-04-17",1823.49],["2015-04-16",1827.38],["2015-04-15",1800.45],["2015-04-14",1762.5],["2015-04-13",1765.96],["2015-04-10",1769.49],["2015-04-09",1771.66],["2015-04-08",1784.82],["2015-04-07",1782.5],["2015-04-02",1782.32],["2015-04-01",1789.78],["2015-03-31",1790.66],["2015-03-30",1783.12],["2015-03-27",1787.0],["2015-03-26",1780.5],["2015-03-25",1786.79],["2015-03-24",1794.37],["2015-03-23",1800.0],["2015-03-20",1780.04],["2015-03-19",1778.69],["2015-03-18",1781.37],["2015-03-17",1776.5],["2015-03-16",1781.0],["2015-03-13",1761.81],["2015-03-12",1764.74],["2015-03-11",1764.02],["2015-03-10",1780.5],["2015-03-09",1785.81],["2015-03-06",1799.77],["2015-03-05",1797.5],["2015-03-04",1797.5],["2015-03-03",1801.45],["2015-03-02",1828.0],["2015-02-27",1808.0],["2015-02-26",1806.11],["2015-02-25",1818.5],["2015-02-24",1795.0],["2015-02-23",1808.5],["2015-02-20",1818.5],["2015-02-19",1821.5],["2015-02-18",1819.5],["2015-02-17",1829.0],["2015-02-16",1843.04],["2015-02-13",1850.25],["2015-02-12",1827.0],["2015-02-11",1836.86]],"collapse":null,"order":null,"database_id":13206}}