Add property to object based on its data

I have a list of records (CSV to JSON) where each row has a variable numbers of attributes in its columns. It could be something like Attribute 1 name and Attribute 1 value, and so on for 2, 3, 4...

On the output object, I'd like to make a Record where the name is the key, and it points to an object based on the attribute data (name and value in this case).

So if the product type is (simplified):

const product = type({
  id: "string",
  attributes: type({
    "[string]": type({
      name: "string",
      value: "string"
    }),
  })
})


Then there are two problems:

  1. The attributes property doesn't exist on the type, so it needs to be added. Right now I get a must be an object (was missing) error. How to add that without any type checking, so to speak?
  2. Then I guess I need to pipe the product type and parse all the attributes there, so they can be added to the attributes property, is that right?
Was this page helpful?