I am trying to import countries list and its corresponding timezones using Migration API's JSON parser plugin .

I am trying to import timezones in paragraphs.

I have created a paragraph to import timezones with text fields. I am able to import data if country has only one timezone. But can not import if country has multiple timezones. Multiple timezones are structured as an array in JSON file.

Can anyone guide me how to iterate multi level JSON.

id: countries_timezones_json_import
label: JSON feed of Countries Time Zones.

migration_group: countries_list

  - Countries List JSON Source
  - Countries timezones Import

      - countries_list_migration
  # We use the JSON source plugin.
  plugin: url
  # Specifies the http fetcher plugin.
  data_fetcher_plugin: http
  # Specifies the JSON parser plugin.
  data_parser_plugin: json
    Accept: 'application/json; charset=utf-8'
    Content-Type: 'application/json'

  # One or more URLs from which to fetch the source data.
    - https://del.dog/raw/countries-list

  include_raw_data: true

  item_selector: /

      name: field_country_id
      label: 'Country ID'
      selector: id
      name: field_country_name
      label: 'Country Name'
      selector: name
      name: field_country_iso3
      label: 'Country ISO3'
      selector: iso3
      name: field_country_iso2
      label: 'Country ISO2'
      selector: iso2
      name: field_country_phone_code
      label: 'Country Phone Code'
      selector: phone_code
      name: field_country_capital
      label: 'Country Capital'
      selector: capital
      name: field_country_currency
      label: 'Country Currency'
      selector: currency
      name: field_country_currency_symbol
      label: 'Country Currency Symbol'
      selector: currency_symbol
      name: field_country_native
      label: 'Country Native'
      selector: native
      name: field_country_region
      label: 'Country Region'
      selector: region
      name: field_country_subregion
      label: 'Country Sub Region'
      selector: subregion
      name: field_country_abbreviation
      label: 'Country Abbreviation'
      selector: timezones/0/abbreviation
      name: field_country_gmt_offset
      label: 'Country GMT Offset'
      selector: timezones/0/gmtOffset
      name: field_country_gmt_offset_name
      label: 'Country GMT Offset Name'
      selector: /timezones/0/gmtOffsetName
      name: field_country_tz_name
      label: 'Country TZ Name'
      selector: /timezones/0/tzName
      name: field_country_zone_name
      label: 'Country Zone Name'
      selector: /timezones/0/zoneName

      type: integer


      plugin: default_value
      source: field_country_abbreviation
      default_value: 'NA'

      plugin: default_value
      source: field_country_gmt_offset
      default_value: 'NA'

      plugin: default_value
      source: field_country_currency
      default_value: 'NA'

      plugin: default_value
      source: field_country_tz_name
      default_value: 'NA'

      plugin: default_value
      source: field_country_zone_name
      default_value: 'NA'

  plugin: entity_reference_revisions:paragraph
  default_bundle: country_timezones

  required: {}
  optional: {}

country_timezones paragraph structure I am having difficulty in iterating timezones array. In the JSON Data

I thought of setting item_selector value as /timezones but this array doesnt have a unique identifier and it can also be linked to country.

Edit 1:

So after browsing the available resources I am able to process the input data to add unique timezoneId to each time zones and respective ids to parent id by creating a data_parser_plugin. Inspired from here

Updated data is in this format.

Now still I am having difficulty to find a way to process sub array. I can not find a way to process the data using sub_process plugin.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.