How to edit existing json file in adf for adding metadata property

Dadheech, Raveesh 41 Reputation points
2024-02-08T13:00:51.1666667+00:00

Hi Team, i am using adf for getting data from sourec and storing data into json format (array of object ) . Data storing correctly but i want to append few things on that out put file and store back that with new json file . Data format of output file is :

[
        {
            "Address1": null,
            "Address2": null,
            "AddressCity": null,
            "ApprovedDate": null,
    }
]
// Data format requited for desired  output after modification by
// addding few static metaadata on just on top of that file as nentioend  below   
{
      "ObjectClass": "ProcurementCompanyData",
    "RowData": [
        {
            "Address1": null,
            "Address2": null,
            "AddressCity": null,
            "ApprovedDate": null,
        }
}
Azure Data Factory
Azure Data Factory
An Azure service for ingesting, preparing, and transforming data at scale.
11,624 questions
0 comments No comments
{count} votes

Accepted answer
  1. Amira Bedhiafi 33,071 Reputation points Volunteer Moderator
    2024-02-08T20:28:39.27+00:00

    ADF doesn't directly modify files but allows you to read data from a source, transform it, and then output it to a destination. Then develop a Databricks notebook that reads your JSON file, performs the necessary transformation by adding the metadata, and then writes the modified JSON back to the desired location.

    import json
    
    # Simulate reading a JSON file
    data = [
        {"Address1": None, "Address2": None, "AddressCity": None, "ApprovedDate": None}
    ]
    
    # Add metadata
    modified_data = {
        "ObjectClass": "ProcurementCompanyData",
        "RowData": data
    }
    
    # Write the modified JSON to a file (or back to a storage service)
    with open('modified_data.json', 'w') as f:
        json.dump(modified_data, f, indent=4)
    
    

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.