Forum Discussion

jamienourish's avatar
jamienourish
Frequent Visitor
7 years ago
Solved

Extract string from json object/array when using DirectQuery mode

Hi,   How can I extract a string from this json, when using DirectQuery mode.   I either have 1 object {"label":"a label","value":"a value"} and would like to pull out the value.   or an arra...
  • v-jiascu-msft's avatar
    v-jiascu-msft
    7 years ago

    Hi jamienourish,

     

    If all the strings have the same format, please try out the formulas below as calculated columns. The functions we can use are limited due to the limitation of Direct Query. 

    FirstValue =
    VAR startNum =
        FIND ( """value"":", [json_filed], 1, 9999 ) + 9
    VAR chars =
        FIND ( """}", [json_filed], 1, 9999 ) - startNum
    RETURN
        MID ( [json_filed], startNum, chars )
    
    SecondValue =
    VAR firstPosition =
        FIND ( """value"":", [json_filed], 1, 9999 ) + 9
    VAR secondPosition =
        FIND ( """value"":", [json_filed], firstPosition, 9999 ) + 9
    VAR chars =
        FIND ( """}]", [json_filed], 1, 9999 ) - secondPosition
    RETURN
        IF (
            FIND ( "[", [json_filed], 1, 9999 ) <> 9999,
            MID ( [json_filed], secondPosition, chars ),
            BLANK ()
        )
    

    Extract-string-from-json-objectarray-when-using-Direct-Query-mode2

     

    Best Regards,
    Dale