Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

161
Views
Can I use an array as metadata value?

I'm trying to create a product in Stripe (using Next.js + Node) with a metadata of the following format:

metadata: {categories: ['foo', 'bar']}

but it seems I can't workaround string-only values in metadata.

Creating a product in the stripe dashboard with brackets in the metadata value result in, when being retrieved:

categories: "['foo', 'bar']"

Trying to create with Node:

const new_product = await stripe.products.create({
      name: 'new product',
      metadata: {categories: ['foo', 'bar']}
})

resulted in:

Error: Invalid value type: {:"0"=>"foo", :"1"=>"bar"} must be a string

This confirms that the value must be a string. The docs were kind of unclear as to the specific type allowance:

You can specify up to 50 keys, with key names up to 40 characters long and values up to 500 characters long.

But I suppose I'm stuck with string values in the metadata.

What is the best workaround for this?

I know I can loop through an object as long as its keys are indices, but I also will want more metadata keys and values. String delimination using split just sounds like a pain. I'm certain there are more ways to effectively use JS objects, but I'm trying to go as simple as possible, as non-developers will also want to make products that follow this archetype.

Thank you for any help.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Stripe stores this data as a single string and AFAIK there is no way around that.

However, when using a Stripe library like the one for Node.js, it does the conversion of the string into an object you can traverse. I created a product with the same categories as the code you shared and was able to access the .categories property using dot notation.

const getProduct = async (id) => {
  console.log("Fetching product to evaluate metadata");
  const product = await stripe.products.retrieve(id)
  const meta = product.metadata
  // console.log(meta);
  console.log(meta.categories); 
}

node test.js
Fetching product to evaluate metadata
["foo", "bar"]
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!