Score:0

Use Migrate Tools to import into multiple value link field from JSON array

cn flag

I am trying to import data into a multi-value link field from a JSON source using Migrate Tools. I think I should be able to do this without writing a custom plugin, but so far nothing is working. My JSON looks like this:

[
 {
  "first_name": "Joe"
  "last_name": "Smith"
  "departments": [
     {
       "department_name": "Mail room"
       "department_url": "https://myoffice.com/mailroom"
     },
     {
       "department_name": "Receiving"
       "department_url": "https://myoffice.com/receiving"
     }
   ],
 },
 { . . . etc }
]

The department_name and department_url values would be the title value and uri value for a multi-value link field. I have tried using the sub_process plugin by configuring the migration config this way:

- name: department_data
  label: "Department data"
  selector: departments

...

process:
   field_department_link:
      plugin: sub_process
      source: department_data
      process:
        'field_department_link/title': department_name
        'field_department_link/uri': department_url

I should note that this migration config is working overall, as I have a number of straight-up text fields that are importing just fine, so I know the issue is specific to how I'm trying to handle this particular field. Also please note that I don't have any control over the JSON itself. It's generated by a third-party application to which I don't have access.

Score:0
cn flag

Got it figured out. Here's the process section of the config file for the multi-value link field:

process:
  field_department_link:
    plugin: sub_process
    source: department_data
    process:
      uri: department_url
      title: department_name
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.