ADF - Variables as type object

Kothai Ramanathan 946 Reputation points Microsoft Employee
2020-09-08T09:51:09.063+00:00

I see that the parameters in a pipeline can be of type object, but there is no option to have a variable as an object type.

I am setting a variable in one pipeline and from another pipeline, I am fetching the details of this set activity, to get the value of that variable. Now it would help if this variable was a json object, so that I can manipulate the values in the object accordingly. Currently I am not able to do this - it will become complicated/messy if I try to do this with string/array (which are the other types applicable for the variable).

Azure Data Factory
Azure Data Factory
An Azure service for ingesting, preparing, and transforming data at scale.
11,345 questions
0 comments No comments
{count} votes

Accepted answer
  1. MartinJaffer-MSFT 26,236 Reputation points
    2020-09-08T18:07:56.213+00:00

    Hello @Kothai Ramanathan and thank you for your question. Please allow me to demonstrate how to convert and manipulate in an easier way than direct string parsing.

    In this (attatched) pipeline, I start with an object parameter:
    {"id":1,"complex":{"foo":"bar","val":true}}

    I will show how to convert to string, and back, then extracting a property.
    23322-image.png
    Suppose I need to store my object into a variable. What I do is use a string type variable and cast the object to string.
    @string(pipeline().parameters.input)
    Note that doing so adds in escape characters.
    23288-image.png

    Next I will parse it back from string to object, and extract a property.
    @json(variables('asString')).complex.foo
    The json() un-escapes and converts into an object. Then I can extract individual properties.
    23298-image.png

    If I wanted to get the boolean property val I can do that and store in a boolean type variable instead of string.

    If I wanted to capture a complex sub-object rather than a single primitive property, I would need to convert back to string again.
    @string( json(variables('asString')).complex )

    In rare cases I have seen json stored as string inside another object. In such cases I have used multiple json() calls to achieve my objectives.

    23341-objecthandle.txt

    Please let me know if this helps or if you have any questions.
    Thank you
    Martin

    1 person found this answer helpful.

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.