Search code examples
jsonapibackendspawnfaker

Spawn strings instead of objects on JsonServer.io


I'm using the JsonServer.io to mock my backend API, but I struggle with the spawn of string values. Is there a possibility to do this? I managed it to spawn one or more objects, but in my usecase I have to spawn string values instead.

I would expect to get a result like this:

"categories": [
    "category-one",
    "category-two",
    "category-three",
    ...
]

Solution

  • For spawning a property as array by its value, your have to do a similar expression like to spawn objects, just use it behind the value you need instead of using it at property name.

    "categories": "expression|spawn(5)"
    

    This will generate the expected array.