Converting PageData to Json

Vote:
 

Hi,

I would like to export all pages or a specific pagetype into JSon so we can export the data into another CMS.

Is this possible?

We are currenlty using Episerver 7.10.

Thanks

Jon

#211131
Dec 18, 2019 13:27
Vincent - Jan 17, 2020 13:32
Have you tried the following package?

https://github.com/joseftw/JOS.ContentSerializer
Vote:
 

There is built in export functionality but it doesn't export in json though. 

You can rename export file to .zip and unpack it and you will get an xml file with properties etc

#211132
Edited, Dec 18, 2019 13:35
Vote:
 

What does ToRawPage do?

#211141
Dec 18, 2019 14:43
Vote:
 

ToRawPage is obsolete, but it creates RawContentInfo.

Consider EPiServer.Core.Transfer.Internal.IRawContentRetriever instead.

#211142
Dec 18, 2019 15:04
Vote:
 

You can always serialize it yourself using Newtonsoft json serializer. I think you will need to configure the serialization a bit though since PageData is quite a deep structure.
I've done that a couple of times to log pages. 

#211145
Dec 18, 2019 15:38
Vote:
 

I wonder if it is possible to get the json from FIND

#211146
Dec 18, 2019 15:44
Vote:
 

Find is json already and if you "hijack" the response coming back (that is an ordinary elastic response so you could do it with for example NEST) you will get it in Find-Json.

#211157
Dec 18, 2019 18:03
Vote:
 

I've seen a few times that json serializing the ContentData throws exception due to circular references and/or complex objects.

I would suggest that you create your own json serialization, or use the serialization from Content Delivery API in your custom API Controller that lists ALL your Content, or something that saves the json into a file.

Quick example:

public IHttpActionResult Get()
{
    IEnumerable<IContent> contentToExport = GetContentToExport();
    var contentModelMapperFactory = ServiceLocator.Current.GetInstance<IContentModelMapperFactory>();

    List<ContentApiModel> contentApiModelList = new List<ContentApiModel>();

    foreach (IContent content in contentToExport)
    {
        IContentModelMapper mapper = contentModelMapperFactory.GetMapper<IContent>(content);
        contentApiModelList.Add(mapper.TransformContent(content, false, "*"));
    }

    return new ContentApiResult<IEnumerable<ContentApiModel>>(contentApiModelList, HttpStatusCode.OK);
}
#215833
Jan 15, 2020 13:26
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.