skip to Main Content

I am creating Azure Data Factory pipeline using Python SDK (azure.mgmt.datafactory.models.PipelineResource). I need to convert PipelineResource object to JSON file. Is it possible anyhow?

I tried json.loads(pipeline_object) , json.dumps(pipeline_object) but no luck.

2

Answers


  1. you can use this.

    # Create a copy activity
    act_name = 'copyBlobtoBlob'
    blob_source = BlobSource()
    blob_sink = BlobSink()
    dsin_ref = DatasetReference(reference_name=ds_name)
    dsOut_ref = DatasetReference(reference_name=dsOut_name)
    copy_activity = CopyActivity(name=act_name,inputs=[dsin_ref], outputs=[dsOut_ref], source=blob_source, sink=blob_sink)
    
    #Create a pipeline with the copy activity
    
    #Note1: To pass parameters to the pipeline, add them to the json string params_for_pipeline shown below in the format { “ParameterName1” : “ParameterValue1” } for each of the parameters needed in the pipeline.
    #Note2: To pass parameters to a dataflow, create a pipeline parameter to hold the parameter name/value, and then consume the pipeline parameter in the dataflow parameter in the format @pipeline().parameters.parametername.
    
    p_name = 'copyPipeline'
    params_for_pipeline = {}
    
    p_name = 'copyPipeline'
    params_for_pipeline = {}
    p_obj = PipelineResource(activities=[copy_activity], parameters=params_for_pipeline)
    p = adf_client.pipelines.create_or_update(rg_name, df_name, p_name, p_obj)
    print_item(p)
    
    Login or Signup to reply.
  2. I need to convert PipelineResource object to JSON file. Is it possible anyhow?

    You can try the following code snippet as suggested by mccoyp:

    You can add a default argument to json.dumps to make objects that are not JSON serializable into dict

    import json
    from azure.mgmt.datafactory.models import Activity, PipelineResource
    
    activity = Activity(name="activity-name")
    resource = PipelineResource(activities=[activity])
    
    json_dict = json.dumps(resource, default=lambda obj: obj.__dict__)
    print(json_dict)
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search