# Unusual behaviour of pointer in json\_foreach

**URL:** https://community.mp3tag.de/t/unusual-behaviour-of-pointer-in-json-foreach/64047
**Category:** Fixed Bugs
**Tags:** bug-fixed
**Created:** [March 12, 2024, 2:57pm UTC](https://community.mp3tag.de/t/unusual-behaviour-of-pointer-in-json-foreach/64047 "2024-03-12T14:57:52Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![rboss](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/r/5f9b8f/32.png) [@rboss](https://community.mp3tag.de/u/rboss)
#### Post date: [March 12, 2024, 2:57pm UTC](https://community.mp3tag.de/t/unusual-behaviour-of-pointer-in-json-foreach/64047/1 "2024-03-12T14:57:53Z")

</div>

Hello,

I have seen different descriptions of this bug in other topics,

> [@\[F\] Web Sources "json\_foreach" command problem](https://community.mp3tag.de/t/f-web-sources-json-foreach-command-problem/18956):
>
> every "json\_\*" commend after the second "json\_foreach\_end" is not working. Total output: output["CurrentUrl"]= "https://api.douban.com/v2/music/search?q=%E4%B8%89%E5%8D%81%E8%80%8C%E7%AB%8B" output["Output"]= "周杰伦, |||||| 胡彦斌, |||||| 任震昊, |||||| 宝儿 (BOA), |||||| Staycool, |||||| 丁丁與西西, DINGDING & SHISHI, |||||| 腰樂隊, |||||| PiA, |||||| PiA, 柴郡貓, |||||| 嬉班子樂團, |||||| 陳妍元, |||||| 吳蓓雅, |||||| 啾吉惦惦, |||||| PiA, |||||| 森林ㄌㄜˋ園, |||||| 廢結合, |||||| Gray spiral, |||||| 孟慶而, |||||| 23號半, |||||| 好事花生樂團, …

> [@\[F\] bug with json\_foreach](https://community.mp3tag.de/t/f-bug-with-json-foreach/16851/3):
>
> QUOTE (Leftaf @ May 9 2015, 21:08) \<{POST\_SNAPBACK}\> Hi mp3taglover fully right we need a do { code block to be executed } while (condition); does any one has some syntax for us?! well, there is actually Do ... While S n Execute the command surrounded by the two commands while S occurs on current position. The optional second parameter limits the execution of the loop to maximal n times. Do MoveLine 1 While "\<td\>" Nesting of Do commands is not allowed. but nesting is not allowe…

but apparently in 3.24a it showed up again.

When working in JSON input mode, navigating to a nested array and using `json_foreach` will return the selected elements of that array correctly. However, after `json_foreach_end` the current pointer jumps to the root of the JSON data instead of the expected behavior of going up one level to the json object where said array is nested.

What I found additionally (and could not find any mentions of) is that if immediately after `json_foreach_end` a `json_unselect_object` is added, the pointer now acts as if it were where it should be -one level above the target nested array- and so moves to the 2nd level above the nested array.

So there are 2 positions for the current pointer after `json_foreach_end`? Is there some kind of memory leak that causes this situation?

This behavior has been reported as a bug before -and reported as fixed; so I am reporting it again, with my findings.

Thank you.

---

<div class="post-metadata">

### Author: ![Florian](https://community.mp3tag.de/user_avatar/community.mp3tag.de/florian/32/5759_2.png) [@Florian](https://community.mp3tag.de/u/Florian)
#### Post date: [March 14, 2024, 10:54am UTC](https://community.mp3tag.de/t/unusual-behaviour-of-pointer-in-json-foreach/64047/2 "2024-03-14T10:54:48Z")

</div>

Can you provide a minimal example which shows the two issues you've mentioned. I'm not sure if it's the same as in the topics you've linked to and it's always hard to debug those without a concrete example.

Thanks!

---

<div class="post-metadata">

### Author: ![rboss](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/r/5f9b8f/32.png) [@rboss](https://community.mp3tag.de/u/rboss)
#### Post date: [March 15, 2024, 3:12pm UTC](https://community.mp3tag.de/t/unusual-behaviour-of-pointer-in-json-foreach/64047/3 "2024-03-15T15:12:00Z")

</div>

Of course.

I will be sending you via direct message an example script in which I was able to replicate the issues, along with some details of what I intended the script to do to get those results.

Oh, and the 2nd quote I mentioned in the previous post wasn't referring the reported bug where it was from, but to the specific line

> [@\[F\] bug with json\_foreach](https://community.mp3tag.de/t/f-bug-with-json-foreach/16851/3):
>
> it's all because json\_foreach\_end goes to the root of the array after finishing i think instead of just going to the same element which was selected first.

which fit what I was also observing.

---

<div class="post-metadata">

### Author: ![rboss](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/r/5f9b8f/32.png) [@rboss](https://community.mp3tag.de/u/rboss)
#### Post date: [April 5, 2024, 1:25pm UTC](https://community.mp3tag.de/t/unusual-behaviour-of-pointer-in-json-foreach/64047/4 "2024-04-05T13:25:38Z")

</div>

Quick update for anyone following this thread:

I sent an example script the same day I wrote the post about it; and Florian has received and tested it for the issue.  
I've also sent a message with suggestions on how to minimize the impact the issue causes, but for some reason haven't received a reply (this was on March 23rd).

I'm assuming he either hasn't noticed or has been too busy to reply; and I'm also guessing that is the same reason why the status of this bug report is still `bug-awaiting-feedback`.

---

<div class="post-metadata">

### Author: ![Florian](https://community.mp3tag.de/user_avatar/community.mp3tag.de/florian/32/5759_2.png) [@Florian](https://community.mp3tag.de/u/Florian)
#### Post date: [April 5, 2024, 3:42pm UTC](https://community.mp3tag.de/t/unusual-behaviour-of-pointer-in-json-foreach/64047/5 "2024-04-05T15:42:16Z")

</div>

> [@rboss](#):
>
> I'm assuming he either hasn't noticed or has been too busy to reply;

It's the latter and I'm sorry.

---

<div class="post-metadata">

### Author: ![rboss](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/r/5f9b8f/32.png) [@rboss](https://community.mp3tag.de/u/rboss)
#### Post date: [April 6, 2024, 11:23pm UTC](https://community.mp3tag.de/t/unusual-behaviour-of-pointer-in-json-foreach/64047/6 "2024-04-06T23:23:02Z")

</div>

No problem.  
Good things take time.

---

<div class="post-metadata">

### Author: ![Florian](https://community.mp3tag.de/user_avatar/community.mp3tag.de/florian/32/5759_2.png) [@Florian](https://community.mp3tag.de/u/Florian)
#### Post date: [April 26, 2024, 8:40am UTC](https://community.mp3tag.de/t/unusual-behaviour-of-pointer-in-json-foreach/64047/7 "2024-04-26T08:40:38Z")

</div>

We took the rest of the testing and fixing off to private conversation and the issue is now fixed with [Mp3tag v3.25a](https://community.mp3tag.de/t/455).

Thanks to @rboss for reporting this and for taking the time for extensive tests 🙏

---

<div class="post-metadata">

### Author: ![system](https://community.mp3tag.de/uploads/default/original/2X/c/ce7035d426cb755a7916793326d23b465222a407.png) [@system](https://community.mp3tag.de/u/system)
#### Post date: [May 26, 2024, 8:41am UTC](https://community.mp3tag.de/t/unusual-behaviour-of-pointer-in-json-foreach/64047/8 "2024-05-26T08:41:18Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
