mshah49rs
mshah49rs

Reputation: 35

How can I turn a cosmosdb list of documents into a hashmap and append values to it

I am currently trying to turn my list of documents I am getting from a cosmosdb query into a map so that I can iterate over the objects elements without using their ids. I want to remove some elements, and I want to append some data to elements as well. Finally I want to output a Json file with this data. How can I do this?

For example:

{
    "action": "A",
    "id": "138",
    "validate": "yes",
    "BaseVehicle": {
        "id": "105"
    },
    "Qty": {
        "value": "1"
    },
    "PartType": {
        "id": "8852"
    },
    "BatchNumber": 0,
    "_attachments": "attachments/",
    "_ts": 1551998460
}

Should Look something like this:

  "type": "App",
  "data": {
    "attributes": {
      "Qty": {
        "values": [
          {
            "source": "internal",
            "locale": "en-US",
            "value": "1"
          }
        ]
      },
      "BaseVehicle": {
        "values": [
          {
            "source": "internal",
            "locale": "en-US",
            "value": "105"
          }
        ]
      },
      "PartType": {
        "values": [
          {
            "source": "internal",
            "locale": "en-US",
            "value": "8852"
          }
        ]
      },
    }
  }
}

Upvotes: 1

Views: 666

Answers (1)

Jay Gong
Jay Gong

Reputation: 23782

You could use Copy Activity in Azure Data Factory to implement your requirements.

1.Write an API to query data from cosmos db and process data into the format you want using code.

2.Output the desired results and configure http connector as source of copy activity.Refer to this link.

3.Configure Azure Blob Storage as sink of copy activity.The dataset properties supports JSON format.Refer to this link.

Upvotes: 1

Related Questions