Can Azure Data Factory transform a string from Oracle (an xml) to a JSon Object to save in a collection in Cosmos as a Object? I've tried, but I only get a string (json object) as a simple attribute in Cosmos DB.
            Asked
            
        
        
            Active
            
        
            Viewed 153 times
        
    1
            
            
        - 
                    Hi,Pedro.How did you configure the adf source and sink.How does the string attribute looks like in cosmos db?Please share it, thank you? – Jay Gong Aug 31 '18 at 01:52
 - 
                    Hi,any progress ? – Jay Gong Aug 31 '18 at 06:29
 - 
                    I'm just started to work. I'm going to report. Thank you. – Pedro Rozo Aug 31 '18 at 13:38
 - 
                    @JayGong. Ok. My previous coworker define a atribute val_documento (String) in Cosmos, so in the mapping, adf just shows a mapping between two string attributes. I´m going to try with the DB Trigger. – Pedro Rozo Aug 31 '18 at 14:07
 
1 Answers
0
            Per my experience, azure data factory can transfer data, but will not help you do some serialization steps. So, you data stored in cosmos db maybe like "info": "{\"Id\":\"1\",\"Name\":\"AA\",\"Address\":\"HQ - Main Line\"}". 
To handle with this solution, I suggest you using Azure Function Cosmos DB Trigger. Please refer to my code:
using System;
using System.Collections.Generic;
using Microsoft.Azure.Documents;
using Microsoft.Azure.Documents.Client;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host;
using Newtonsoft.Json.Linq;
namespace ProcessJson
{
    public class Class1
    {
        [FunctionName("DocumentUpdates")]
        public static void Run(
        [CosmosDBTrigger(databaseName:"db",collectionName: "item", ConnectionStringSetting = "CosmosDBConnection",LeaseCollectionName = "leases",
            CreateLeaseCollectionIfNotExists = true)]
        IReadOnlyList<Document> documents,
        TraceWriter log)
        {
            log.Verbose("Start.........");
            String endpointUrl = "https://***.documents.azure.com:443/";
            String authorizationKey = "***";
            String databaseId = "db";
            String collectionId = "import";
            DocumentClient client = new DocumentClient(new Uri(endpointUrl), authorizationKey);
            for (int i = 0; i < documents.Count; i++)
            {
                Document doc = documents[i];
                String info = doc.GetPropertyValue<String>("info");
                JObject o = JObject.Parse(info);
                doc.SetPropertyValue("info", o);
                client.ReplaceDocumentAsync(UriFactory.CreateDocumentUri(databaseId, collectionId, doc.Id), doc);
                log.Verbose("Update document Id " + doc.Id);
            }
        }
    }
}
In addition,you could refer to my previous case:Azure Cosmos DB SQL - how to unescape inner json property
Hope it helps you.
        Jay Gong
        
- 23,163
 - 2
 - 27
 - 32