How to create JSON feeds to export and import content

Dear all,

We have added a how to on how to create JSON feeds in order to export content from and import content into your website.

You can find it here.

1 Like

Hello Sotirios,

the link seems to be broken.

I am looking for a way to export some data from Drupal 7 and import it into Drupal 8. In particular all content of a given Content Type (EN-CV Project).

This is content the customers changed a lot in Drupal 7 site during the current migration.

Thanks

Hi Juan,

I have updated the link https://drupal-tools.web.cern.ch/how-to/create-feeds-to-import-content

Hi Sotirios,

thanks for the update. Is this also the way to export the content from Drupal 7? I just find the way to do the import.

Thanks

Hi Juan,

Go to your Drupal 7 website and install this module https://www.drupal.org/project/views_datasource

This will allow you to export the content in JSON format via Views.

Once you have installed it create a view with format ‘JSON Data Document’ to display fields from the content type you want. Create a path for the view and go to that path to see your data in JSON.

To import the data from the JSON feed into your Drupal 8 website follow the guide on Drupal tools website.

You need the module Feeds extensible parsers https://www.drupal.org/project/feeds_ex and enable Ludwig module as well for the external libraries. It’s all explained in the How To.

Once you have set all these up go to Structure->Feed types and create a new Feed with parser ‘JSONPath’, set up the mappings between the feed and the content type and Save.

Then go to Content, click on the Feeds tab and create a new Feed of type of the one you just created in Feed types and enter the URL of Drupal 7 website’s JSON Feed and import.

Ok great, I will try
Thanks

Hi again,

ok I already installed and configured everything. Also created both the mapping and the feed.
I also validated the generated JSON file and it is valid. However, I get this error:
image
It shows a syntax error which I don’t find and also that there are no new EN-CV projects.

I entered this context:
$.nodes.node.*

Not sure it is fine but I tried different options without success.

My JSON file is like this (including much more fields):
{
“nodes” : [
{
“node” : {
“title” : “test Juan”,
“Data gathering start date” : “”,
“FSU” : “Juan G.”,
"I/O tests In situ Start Date " : “”,
“Project Details” : “”,
“Project leader” : “Juan G.”,
“Project number” : “PTEST01”,
“Data gathering End Date” : “”,
“Electrical Schema” : “No”,
“Electrical Schema comments” : “”,
“I/O List Contractor” : “No”,
“Status (manual set)” : “Pipeline”
}
}
]
}

It is available here:
https://en-cv.web.cern.ch/data-export-encv-project

Any idea what I’m missing?

Thanks,
Juan

Hi Juan,

The JSON feed should be be accessible anonymously and not behind SSO.

Also, what is the URL of your Drupal 8 website?

Hi,

Ok, I changed the access and same problem.
D8 site is https://test-en-dep-cv-cl-v2.web.cern.ch/

Hi Juan,

The Context value in mapping is wrong $.nodes.node.*

It should be $.nodes.*.node.* because your feed’s structure is nodes.0.node.data

If you still have a problem after that, remove the spaces from the source fields and try again.

Same result.
I updated also the output format to Raw and removed newlines. Is that what you mean?

The configuration of your D7 JSON feed should be like in the image below:

Then in your D8 website in mappings the context field value should be $.nodes.node.*

Also, your feed it’s still behind SSO. Open an incognito window and you will see that it asks for credentials. It should be accessible by anonymous users.

Not sure how to disable SSO, I think it is configured to be centrally managed at CERN. Also I shouldn’t disable it for the whole site.

I

I will try to figure out another way. It should be a way to just use the generated JSON file to import the data.

Hi Juan,

If you want me to take a look at the D7 website you can add me as admin in the administration e-group. I don’t have admin access to D7 websites.

I think that there is something wrong with the access rights of this view or with the permissions in general ‘View published content’ and which roles can access it.

I added you as admin.

Ok this took a few hours to debug.

When you visit a Drupal 7 website in https it forces SSO. So your link should have been http and not https.

Anyway even with http the view was not accessible because the EN-CV content type is using the Content Access module and is set so anonymous users can’t see nodes of this content type. So I changed its settings here https://en-cv.web.cern.ch/admin/structure/types/manage/cv-project-new-template/access

Even after this change the view still was not accessible and this is because you use the Field Permission module and it was enabled for the field Status so no anonymous users can see it. I have changed the settings here https://en-cv.web.cern.ch/admin/structure/types/manage/cv-project-new-template/fields/field_conditional_status

After I cleared the caches and the URL was accessible as anonymous.

I tried to import the feed in your Drupal 8 website but was giving me errors due to the spaces in the Feed’s fields. I had to remove all the fields from Drupal 7 view because they had spaces in their labels here https://en-cv.web.cern.ch/admin/structure/views/view/data_export_encv_project/edit and make a test only with three fields and replacing the spaces with underscore (e.g. project_number).

Then I went back to your Drupal 8 website and I setup a new Feed in Feed types called EN-CV Project JSON Feed https://test-en-dep-cv-cl-v2.web.cern.ch/admin/structure/feeds/manage/en_cv_project_json_feed

I set the Fetcher value to Download from URL and the Context value under mapping to $.nodes.*

Then in mappings I mapped only three fields for the test (Title, Project number and Status). To map them correctly you select the Target field and then in the Source field you click the dropdown list and select New source… and you type the name of the field exactly as it is in the Drupal 7 JSON feed.

Once I did the mapping I went to Content, Feeds tab and I created a new feed called EN-CV Project JSON Feed https://test-en-dep-cv-cl-v2.web.cern.ch/feed/4/edit and I entered the Drupal 7 JSON Feed URL and clicked Save and Import.

As you can see from the images below the content was imported successfully.

What you have to do now is to add again the fields in the Drupal 7 view without spaces in their labels and then go to your Drupal 8 website and finish the rest of the mapping and everything will work fine.

After the import is done you can revert the changes in Content Access and Field Permission for the EN-CV content type so they are not accessible by anonymous anymore.

1 Like

Hello Sotirios,

Thank you, I will include all the fields to check how it works. The Drupal 7 site wasn’t developed by me and contains a lot of customization and modules, that’s why I get into troubles constantly… Plus I’m not a Drupal expert…

I also managed to import some content using the CSV import module yesterday. I used the exported JSON file as a CSV. I had to format the content a litle bit and it seems to work quite well. Not sure how it will work with complex fields but I had issues with date formats (solved now).

I will check how both modules works with larger contents today and let will let you know.

In any case, I owe you a coffee. :slight_smile:

Thanks,
Juan