No internet connection
  1. Home
  2. General

Extract Field from Json using Foreach iteration counter

By Jason @Jase
    2022-07-07 13:05:03.596Z

    Good day!

    I'm looping through JSON and using the Iteration count to select the relevant block for that member.

    If I hard code into the Extract Field, Extract from Json


    It returns the data expected but when using the iteration counter


    It always returns the first element [0] in the Json.

    I've outputted the %Child_Member_Count% and can confirm it is iterating and counting up but it appears the Extract Field is ignoring it.

    • 5 replies
    1. L
      Liam @liam
        2022-07-07 13:06:52.261Z

        Hi Jason

        Is it possible for you to share a screenshot of your config, so I can get a little more context on where these values are set.
        I can then attempt o replicate the issue a little more easily.

        1. JJason @Jase
            2022-07-07 14:25:30.437Z

            %Child_Member_Count% is incrementing, I'm logging the output which proves this but when used in the Extract Field it's always returning the first object in the array.

            Here is a trimmed version of the Json I'm working with.

            		"company": "Enterprise",
            		"title": [
            			"TEST TEST TEST",
            			"TEST TEST TEST"
            		"reference": [
            		"description": {
            			"#cdata-section": "THIS IS A TEST THIS IS A TEST
            		"duration": "1 year",
            		"email": "",
            		"location": "BRIGHTON, BN1 123"
            		"company": "Enterprise",
            		"title": [
            			"Quality Administrator",
            			"Quality Administrator"
            		"reference": [
            		"description": {
            			"#cdata-section": "<p>&#13;&#10;    <strong>Quality Administrator</strong>&#13;&#10;</p>&#13;&#10;"
            		"duration": "",
            		"email": "",
            		"location": "Beaconsfield"
            1. LLiam @liam
                2022-07-07 14:29:36.959Z

                Thanks Jason

                The developers have said they will be able to fix this, I'd keep an eye out on the next release notes, or opt into the pre-release builds to see the change sooner.

                1. JJason @Jase
                    2022-07-08 13:01:41.962Z

                    Thank you Liam. I have received the update today and it's fixed.

                    Could I ask that the Iteration Counter has the ability to start from 0? Even though I set the variable that is being iterated to 0 it appears that the iteration happens as the Loop starts so it always starts at 1 but when working with an Arrays we need to start at 0.

                    1. LLiam @liam
                        2022-07-08 13:56:55.064Z

                        Hi Jason

                        The devs will look at having this as an option, we can't easily change the default behaviour at this point, due to the potential impact on existing setups.
                        Alternatively you can use the Set Variable action to subtract 1 from the count value, so it is correct for your arrays

                2. Progress
                  with handling this problem
                3. L@liam marked this topic as Planned 2022-07-07 14:28:31.443Z.