web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Attachment Field empty...
Power Automate
Answered

Attachment Field empty Parse JSON failed

(1) ShareShare
ReportReport
Posted on by 31

Hi,

I've seen a few responses to how to update the Parse JSon code to get Flow to bypass it if the field is left blank, but I've not seen anything that explained explicitly where they update code goes.

 

In my case, I'm trying to bypass an attachment upload field. If anyone could help me bypass Parse JSON when the field "Attach Terms" is left blank I will be very grateful. 

 

the Schema is as follows:

{
    "type""array",
    "items": {
        "type""object",
        "properties": {
            "name": {
                "type""string"
            },
            "link": {
                "type""string"
            },
            "id": {
                "type""string"
            },
            "type": {},
            "size": {
                "type""integer"
            },
            "referenceId": {
                "type""string"
            },
            "driveId": {
                "type""string"
            },
            "status": {
                "type""integer"
            },
            "uploadSessionUrl": {}
        },
        "required": [
            "name",
            "link",
            "id",
            "type",
            "size",
            "referenceId",
            "driveId",
            "status",
            "uploadSessionUrl"
        ]
    }
}

 

Screenshot 2022-05-09 143440.png

 

Categories:
I have the same question (0)
  • DamoBird365 Profile Picture
    8,942 Microsoft Employee on at

    Hi @GMorley 

     

    You can use the filter array action (where the field is not empty) and then run your apply to each on this filtered array.

     

    DamoBird365_0-1652119205261.png

     

    As the filtered array does not contain your blank attachment key, it would not be in the array.

     

    Damien

     

  • GMorley Profile Picture
    31 on at

    Hi, Thanks for responding,

     

    Since it's the Parse that's failing, I assume I need to filter before the Parse, not before the Apply to each? The flow isn't getting as far as apply to each.

     

    I'm assuming From should be the Form response ID, and name is the Attach Terms field?

     

    I know I'm asking you to spell it out for me, but this is my first time exploring what flow can do. Thank you for your help.

     

     

  • GMorley Profile Picture
    31 on at

    @DamoBird365

     

    I've had a go but I don't really understand what I'm trying to acheive with the filter.

     

    I thought it was a case of checking the form response for attachements and if it does not contain blank then proceed with the Parse.

     

    But if it doesn't do the Parse because the field was blank, it also wont proceed to send the emails. I want it to send the emails whether or not there is an attachment. I just don't want the flow to fail because a file wasn't attached.

     

    I suppose i could put the emails parallel to the Parse JSON so that the attachments don't effect the emails but the flow will still fail at Parse JSON.

     

    Screenshot 2022-05-10 095736 1.pngScreenshot 2022-05-10 095819 2.png

  • SPOLHE-C Profile Picture
    17 on at

    If you're happy with the flow otherwise, you can adjust the JSON directly to accept a null. In your code sample, where it says "type""string", change that to

    "type": ["string","null"]

    (do the same with "type": "integer" but NOT "type": "array"). 

     

    ...I'll look forward to a more elegant solution in the replies. (Edited to fix a typo.)

  • Verified answer
    eliotcole Profile Picture
    4,363 Moderator on at

    Hi, @GMorley , if I've understood you correctly, the code goes in the Schema. You essentially tell the Schema that it's OK to set a blank value, and not fail the input.

     

    I'll dig it out, but I may have mentioned it on here at some point, too.

     

    Ah, basically what @SPOLHE-C said ... except the array bracket goes teh other side of the field name.

     

    So, I couldn't see AttachTerms in your schema, so I've used "id" as the field that might be without data, I would set that up in the schema like so:

    {
     "type": "array",
     "items": {
     "type": "object",
     "properties": {
     "name": {
     "type": "string"
     },
     "link": {
     "type": "string"
     },
     "id": {
     "type": ["string", "null"]
     },
     "type": {},
     "size": {
     "type": "integer"
     },
     "referenceId": {
     "type": "string"
     },
     "driveId": {
     "type": "string"
     },
     "status": {
     "type": "integer"
     },
     "uploadSessionUrl": {}
     },
     "required": [
     "name",
     "link",
     "id",
     "type",
     "size",
     "referenceId",
     "driveId",
     "status",
     "uploadSessionUrl"
     ]
     }
    }

     

     

  • SPOLHE-C Profile Picture
    17 on at

    Yes, that! (Can't even blame my system, entirely my error when typing.) Thanks for the quick fix.

  • eliotcole Profile Picture
    4,363 Moderator on at

    Honestly no bigs! I hadn't realised you had also posted, so I just swerved around you a bit ;-). Frankly I was just thankful that you had, as it meant I could type it all up a bit quicker! 😅

     

    Also, @GMorley , if you want the whole thing to carry on if the input is nil, then you can use a 'Run after' on the following flow action to ensure that it runs whether or not the JSON parser does its thing. Just make sure that your following actions are capable of dealing with a lack of information there. 😉

     

    However, I think deeper interactions would require a bit more of your flow up here.

     

  • GMorley Profile Picture
    31 on at

    @eliotcole , @SPOLHE-C  thank you for this. I've updated the schema and the flow now works. 

     

    Really appreciate the support. 

  • dominique2001 Profile Picture
    11 on at
    Hi, @eliotcole I I have the same problem as the person who asked this question. I used the code you provided but it did not work for me. Please see my the code below and the error message it gave me:
     
    Error message : InvalidTemplate. Unable to process template language expressions in action 'Parse_JSON' inputs at line '0' and column '0': 'Required property 'content' expects a value but got null. Path ''.'.

    Note: The flow succeeded with attachment but when there is not upload of document, it fails as seen below
     
    {
        "type": "array",
        "items": {
            "type": "object",
            "properties": {
                "name": {
                    "type": "string"
                },
                "link": {
                    "type": "string"
                },
                "id": {
                    "type": [
                        "string",
                        "null"
                    ]
                },
                "type": {},
                "size": {
                    "type": "integer"
                },
                "referenceId": {
                    "type": "string"
                },
                "driveId": {
                    "type": "string"
                },
                "status": {
                    "type": "integer"
                },
                "uploadSessionUrl": {}
            },
            "required": [
                "name",
                "link",
                "id",
                "type",
                "size",
                "referenceId",
                "driveId",
                "status",
                "uploadSessionUrl"
            ]
        }
    }
     
    Please help if you can. I have been trying to fix this for couple of days now. Thank you
     
     
     
  • eliotcole Profile Picture
    4,363 Moderator on at
    Hi, @dominique2001, the problem that you have (sorry) is that you're using Parse JSON ... it will *only* react based on the Schema that you give it ... and it can break if what is feeding that doesn't exactly match, or does things that you haven't accounted for.
     
    I would say that you are probably experienced enough (now) to start directly referencing the body or outputs of an action using the body()?['fieldName'] or outputs()?['body/fieldName'] referencing the fieldnames as you want them.
     
    If you wish to work these out, then use the outputs from a test run to find them, and reference accordingly, or have an test action which runs after the one that you want to get an idea of the fields, and push it out that way.
     
    ---
     
    Otherwise, my suggestion would be to raise a new question in the forum, including what you have below. :)

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 501 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 323 Moderator

#3
abm abm Profile Picture

abm abm 237 Most Valuable Professional

Last 30 days Overall leaderboard