Spawn strings instead of objects on JsonServer.io

Viewed 42

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",
    ...
]
2 Answers

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.

You can also visit the official documentation for more detailed information.

Related