Is there an Array string in Payload CMS?

default discord avatar
IRediTOTO
8 months ago
2 2

Hi, I tried to read the documentation, but I couldn't find it. Is there something to save array string to database?
I just want save array of strings
Ex: ["a","b","c"]
I don't want save array of objects like this, just need array of strings here
image

  • discord user avatar
    jacobsfletch
    Payload Team
    7 months ago

    Thejson field might work for you: https://payloadcms.com/docs/fields/json#json-field

  • discord user avatar
    JessChowdhury
    Payload Team
    8 months ago

    Hi @IRediTOTO, this isn't currently supported but would definitely be useful in many cases. This question was also discussed on discord here. A potential workaround solution would be to:

    1. Create a hidden preferences field
    2. On save, map the original array and return as an array of strings
    3. Pass this new array to your hidden field

    There might be more appropriate workarounds too if you want to share more information on what you're looking to achieve, let us know if you need further help here!

    3 replies
    default discord avatar
    IRediTOTO
    8 months ago

    Thank you for replied me and let me know. Ok fine, but I will wait for a that feature like that. This pretty basic, I think any Payload newbie will ask himself: where is the array??? :D

    default discord avatar
    gaboluque
    7 months ago

    Payload newbie here, I think this could be really useful.

    discord user avatar
    jacobsfletch
    Payload Team
    7 months ago

    The json field might work for you: https://payloadcms.com/docs/fields/json#json-field

Open the post
Continue the discussion in GitHub
Like what we're doing?
Star us on GitHub!

Star

Connect with the Payload Community on Discord

Discord

online

Can't find what you're looking for?

Get help straight from the Payload team with an Enterprise License.