JSON-D8 Migration: By Using Available and Custom Process Plugins
In our XML to Drupal 8 bog post series, we have seen that how can we do the XML to D8 migration by just using YML file, extend the capabilities of the migration by using available Process plugins and finally extended the capabilities of the migration by using Custom Process plugins.
As the JSON to Drupal 8 migration is quite similar to XML migration so we will do the complete JSON to Drupal 8 migration in this Blog post.
As we are migrating from JSON so we have created a sample JSON file which looks like below,
Our migration configuration entity (YML) file under config/install defines Source (JSON file and fields in it), Destination (Drupal entity) and Field mappings (Process plugins). It looks like below,
Data parser plugin is part of Migrate Plus module. It means we don't need to write custom code for most of the cases while migrating from XML or JSON to Drupal 8. The interesting part is that XML and JSON migrations are quite similar. All the available / custom process plugins will be used in same way. Even the source fields are defined in same way. If you compare the migrate_xml_d8_custom and migrate_json_d8_custom custom modules, you will notice that there is just one line change in migration configuration entity (migrate_plus.migration.pages_content.yml)!
Next we have created the custom process plugin in src/Plugin/migrate/process/ContentTypePlugin.php. This custom process plugin uses 'site_url' JSON field to determine the content type (article or basic page) based on the requirements. Custom process plugin needs to be placed under /src/Plugin/migrate/process/ as per the Drupal PSR-4 standards. The plugins in Drupal 8 uses Annotations to define the name of the plugin. Our custom plugin looks like below,
Finally migration has been executed in same way as in XML to D8 migration using "drush mi pages_content" command and we got all the data on D8 site in different content types as expected. It looks like below,

The source code is also available on Git repository.
We can write more custom process plugins based on our requirements and use them to do custom migrations!
As the JSON to Drupal 8 migration is quite similar to XML migration so we will do the complete JSON to Drupal 8 migration in this Blog post.
As we are migrating from JSON so we have created a sample JSON file which looks like below,
Our migration configuration entity (YML) file under config/install defines Source (JSON file and fields in it), Destination (Drupal entity) and Field mappings (Process plugins). It looks like below,
The only change between XML and JSON migration is "data_parser_plugin" as shown below,
Data parser plugin is part of Migrate Plus module. It means we don't need to write custom code for most of the cases while migrating from XML or JSON to Drupal 8. The interesting part is that XML and JSON migrations are quite similar. All the available / custom process plugins will be used in same way. Even the source fields are defined in same way. If you compare the migrate_xml_d8_custom and migrate_json_d8_custom custom modules, you will notice that there is just one line change in migration configuration entity (migrate_plus.migration.pages_content.yml)!
Next we have created the custom process plugin in src/Plugin/migrate/process/ContentTypePlugin.php. This custom process plugin uses 'site_url' JSON field to determine the content type (article or basic page) based on the requirements. Custom process plugin needs to be placed under /src/Plugin/migrate/process/ as per the Drupal PSR-4 standards. The plugins in Drupal 8 uses Annotations to define the name of the plugin. Our custom plugin looks like below,
Finally migration has been executed in same way as in XML to D8 migration using "drush mi pages_content" command and we got all the data on D8 site in different content types as expected. It looks like below,

The source code is also available on Git repository.
We can write more custom process plugins based on our requirements and use them to do custom migrations!



Comments
For more information mens black titanium wedding bands on the new earrings, visit TITanium Arts.com. All products ford fiesta titanium are tested and shipped to titanium nipple bars you with no titanium nitride questions titanium quartz asked!