Forum Discussion

jatpola's avatar
jatpola
Frequent Visitor
5 years ago
Solved

Error handling: JSON field can either be logical or record

Hi, I have a JSON field ("sentiment" in the screenshots ) which can either be "FALSE" or contain a Record. If it's a Record I'd like to access it, otherwise I need some error handling (return null v...
  • PhilipTreacy's avatar
    5 years ago

    Hi jatpola 

    You can separate the steps that come after the try ... otherwise into a function and then call it only if sentiment is not null

    let
    
        ContinueTransforms = (level_1) =>
        let 
            level_2 = level_1[stats],
            level_3 = level_2[metrics],
            level_4 = level_3[score],
            Result = Record.ToTable(level_4)
    
        in Result,
    
        Source = API_JSON,
        level_1 = try Source[sentiment] otherwise null,
    
        #"To Table" = if level_1 is null then null else ContinueTransforms(level_1)
    in
        #"To Table"

    Regards

    Phil