0

I'm currently really busy to get the migration work on my desk. I want to import (migrate) a local json file into drupal8 using Migrate_Plus, Migrate tools. For that I have the following migration yml configuration file


# Migration configuration for products.
id: product
label: 'Product'
migration_group: Products
# Here we define the migration source
source:
  plugin: url
  data_fetcher_plugin: file
  data_parser_plugin: json
  urls: /modules/custom/migrate_products/data/data.json
  item_selector: /data
  fields:
    -
      name: uuid
      label: 'uuid'
      selector: uuid/value

    -
     name: name
     label: 'Produkt Name'
     selector: name/value

    -
      name: supplierName
      label: 'Anbietername'
      selector: supplierName/value

  ids:
    uuid:
     type: string



destination:
    plugin: entity:node

process:
  type:
    plugin: default_value
    default_value: produkt

  title: name
  field_uuid: uuid
  field_suppliername: supplierName

  sticky:
    plugin: default_value
    default_value: 0
  uid:
    plugin: default_value
    default_value: 0

migration_dependencies:
  required: {}
  optional: {}

dependencies:
  enforced:
    module:
      - migrate_products

Like you can see, the json file is located inside the custom module directory.

The json file looks like this:


{
  "data": [
    {
      "uuid": {
        "value": "7d51-4406-a7ef-3a7916b977a9",
        "patient": false
      },
      "name": {
        "value": "Product1",
        "patient": false
      },
      "supplierName": {
        "value": "User1",
        "patient": false
      },
.....

After enbaling the required migration module, when running: drush ms I get the following output:


file parser plugin: could not retrieve data from /modules/custom/migrate_products/data/data.json
 Group: Products (Products)  Status  Total  Imported  Unprocessed  Last imported 
 product                     Idle    n. v.  0         n. v.
0

The data fetcher plugin can't find your JSON file because the format is wrong. The plugin is expecting Drupal's URI format (e.g. public://path/to/data.json or private://path/to/data.json) under its private/public file dir. For example, see the included example migration with the module:

  # The data_parser normally limits the fields passed on to the source plugin
  # to fields configured to be used as part of the migration. To support more
  # dynamic migrations, the JSON data parser supports including the original
  # data for the current row. Simply include the 'include_raw_data' flag set
  # to `true` to enable this. This option is disabled by default to minimize
  # memory footprint for migrations that do not need this capability.
  # include_raw_data: true
  # Flags whether to track changes to incoming data. If TRUE, we will maintain
  # hashed source rows to determine whether incoming data has changed.
  # track_changes: true
  # Copy the example JSON file in artifacts folder to sites/default/files folder.
  urls:
    - 'public://migrate_json_example/products.json'

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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