How can i get data from another data bucket in mockoon

501 Views Asked by At

right now I'm getting an array of [object Object] when trying to get data using dataraw in mockoon data bucket.

data is working but it's not compatible with array helpers like oneOf.

oneOf will return [object Object] with 'dataRaw' and null with 'data'

How can I get the actual value?

Here's my file and data buckets:

addresstypes

[
    {
      "publicId": "{{guid}}",
      "title": "School"
    },
    {
      "publicId": "{{guid}}",
      "title": "Shopcenter"
    },
    {
      "publicId": "{{guid}}",
      "title": "Highway"
    },
    {
      "publicId": "{{guid}}",
      "title": "Home"
    }
]

address

[
  {{# repeat 50}}
    {
      "publicId": "{{guid}}",
      "title": "{{lorem 3}}",
      "street":"{{street}}", 
      "city": "{{city}}", 
      "country":"{{country}} ({{countryCode}})", 
      "zipcode":"{{zipcode}}",
      "postcode":"{{postcode}}",
      "lat":"{{lat}}",
      "long":"{{long}}",
      "type": {{oneOf (dataRaw 'addressetypes')}}
    }
  {{/repeat}}
]

Mockoon version: 3.1.0

OS / OS version: Ubuntu 22.04.2 LTS

1

There are 1 best solutions below

0
ARiyou Jahan On

This is annoying but not really a bug. oneOf is fetching correctly the object inside the data bucket array, but Handlebars stringifies everything by default, so we receive [object Object] which is JS way of representing an object.

You can circumvent this by stringifying the result and avoiding character escaping with triple curly braces:

{{{stringify (oneOf (dataRaw '...'))}}}

I know it's not ideal. I will add a stringify flag to oneOf so it outputs the content stringified and we can avoid using stringify directly + triple curly.