2

I have a module pulling a JSON feed into Drupal 8 using the Migrate API. However, one of the values in the JSON is an array.

For example, coordinates:

{
    "data": [
        {
            "id": "id:1",
            "position": {
                "coordinates": [
                    24.932974,
                    60.168495
                ],
                "type": "Point"
            },
            ...
        },
        {
            "id": "id:2",
            "position": {
                "coordinates": [
                    24.94416,
                    60.18831
                ],
                "type": "Point"
            },
            ...
        },
...

What sort of field selector is needed to get coordinates?

If I use selector: position/coordinates I get 24.932974.

  • How would I get the second one: 60.168495?

  • Should the extract plugin be used here?

2

First, use a selector like this:

-
  name: position
  label: 'Position'
  selector: position

Then use this for the first value:

field_description:
  plugin: extract
  source: position
  index:
    - coordinates
    - 0

And this for the second value:

field_description:
  plugin: extract
  source: position
  index:
    - coordinates
    - 1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.