Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
EDIT: added the yml and fixed the json data (was a copy/paste error)
Problem: Not able to get the data (id or Name) from the "Sets" array. Goal is to create 4 contents out of this data.
This is the source:
{
"Time" : "2019-10-08",
"Centers" : [ {
"id" : "B01502",
"CenterId" : 1502,
"Sets" : [ {
"id" : "B0150200",
"Name" : "name_valuex"
}, {
"id" : "B0150201",
"Name" : "name_valueu"
} ]
}, {
"id" : "B01503",
"CenterId" : 1503,
"Sets" : [ {
"id" : "B0150301",
"Name" : "name_valueb"
}, {
"id" : "B0150302",
"Name" : "name_valuea"
} ]
} ]
}
This is my YML
id: test_data
source:
constants:
TITLE_PREFIX: 'title prefix - '
plugin: url
data_fetcher_plugin: file
data_parser_plugin: json
urls:
- /test.json
item_selector: 1
fields:
- name: id
label: 'id'
selector: id
ids:
id:
type: string
process:
title: constants/TITLE_PREFIX
field_presetid: id
destination:
plugin: 'entity:node'
default_bundle: bundle_name
I have tried to put different values to "item_selector:" like /Centers/Sets or "0" etc.
Modules:
Migrate: Version: 8.7.8
Migrate Plus: Version: 8.x-4.2
Migrate Tools: Version: 8.x-4.4
Drupal: 8.7.8
PHP 7.2.22
Issue fork migrate_plus-3087614
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
jukka792 CreditAttribution: jukka792 as a volunteer commentedComment #3
jukka792 CreditAttribution: jukka792 as a volunteer commentedComment #4
jukka792 CreditAttribution: jukka792 as a volunteer commentedComment #5
heddnCreate a custom source plugin that parses the source and combines all the values into a single array. Use of a PHP generator (yield) is encouraged.
Comment #6
marvil07 CreditAttribution: marvil07 at Tag1 Consulting commentedComment #8
marvil07 CreditAttribution: marvil07 at Tag1 Consulting commentedIt will be nice to have a way to walk through a set of items nested in all the item selector items.
I have started one custom data parser plugin that does that.
It basically extends the json data parser plugin, and then uses a given selector to unify its values across all the elements.
E.g. the following the original example, the following source configuration bits will extract the four items.
On the ideal world, jq pipelines can do the work once, but if the source endpoints cannot be changed, something like this data parser helps to produce a set that is sensible to walk.
New commits on new
3087614-json-subitems
topic branch and related new MR !87.