To_json and polymorphic models

I have tried to use to_json to create an array that will be
manipulated in javascript on the client. The output of to_json looks
something like this:

[{addressable:
{attributes: {code: “123123123”, quantity: “123”, id: “1”,
description: “Window”, unit_price: “12”}},
attributes: {addressable_type: “WorkshopOrderPart”,
workshop_order_id: “1”, addressable_id: “1”, id: “1”, position:
“1”}},
{addressable: …
}}]

You will notice that “attibutes” shows up twice due to the polymorphic
relationship but is not a range so if you assign it to a javascript
array then addressing it goes like this:

newarray[0].addressable.attributes.code

That works but:

newarray[0].addressable.attributes.addressable_type

does not. Anyone know how to go about addressing the “attributes”?