# IfLess and IfGreater not parsing the whole output

**URL:** https://community.mp3tag.de/t/ifless-and-ifgreater-not-parsing-the-whole-output/61569
**Category:** Web Sources Discussion
**Created:** [July 15, 2023, 8:00pm UTC](https://community.mp3tag.de/t/ifless-and-ifgreater-not-parsing-the-whole-output/61569 "2023-07-15T20:00:48Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![stevehero](https://community.mp3tag.de/user_avatar/community.mp3tag.de/stevehero/32/337_2.png) [@stevehero](https://community.mp3tag.de/u/stevehero)
#### Post date: [July 15, 2023, 8:00pm UTC](https://community.mp3tag.de/t/ifless-and-ifgreater-not-parsing-the-whole-output/61569/1 "2023-07-15T20:00:48Z")

</div>

Consider this:

```auto
outputto "_Test"
SayOutput "10"
IfGreater 5
Say "Greater than 5"
Else
Say "Less than 5"
Endif

```

This returns:

```auto
Less than 5

```

Whereas it should be greater @Florian ? Or does this function only check the first digit?

I've done a workaround by doing:

```auto
json_select "track_count"
RegexpReplace "^\s*1\s*$" "True"
If "True"
Say "XXX"
Endif
```

---

<div class="post-metadata">

### Author: ![LyricsLover](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/l/c6cbf5/32.png) [@LyricsLover](https://community.mp3tag.de/u/LyricsLover)
#### Post date: [July 15, 2023, 11:13pm UTC](https://community.mp3tag.de/t/ifless-and-ifgreater-not-parsing-the-whole-output/61569/2 "2023-07-15T23:13:58Z")

</div>

According to the documentation:

 ![image](https://community.mp3tag.de/uploads/default/original/2X/5/5f2e5c60ba12e5e272e279aebbafbd87c30f3e94.png)  
the command `IfGreater` check for a NUMBER not a string like "10".  
What to you get if you `SayOutput 10` (without the quotes)?

Would it work then as expected?

---

<div class="post-metadata">

### Author: ![stevehero](https://community.mp3tag.de/user_avatar/community.mp3tag.de/stevehero/32/337_2.png) [@stevehero](https://community.mp3tag.de/u/stevehero)
#### Post date: [July 15, 2023, 11:51pm UTC](https://community.mp3tag.de/t/ifless-and-ifgreater-not-parsing-the-whole-output/61569/3 "2023-07-15T23:51:33Z")

</div>

`SayOutput` needs to be a string.

The function will probably parse that as an int and do this check I would say but it doesn't seem to get the whole output or in my particular case the `json_select` function which is like so:

```auto
{"track_count": 15}

```

If I check for `IfGreater` than `1` here it returns `False`.

---

<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: [July 16, 2023, 7:33am UTC](https://community.mp3tag.de/t/ifless-and-ifgreater-not-parsing-the-whole-output/61569/4 "2023-07-16T07:33:33Z")

</div>

It seems that there is a slight misunderstanding on how this command is supposed to be working. `IfGreater` and `IfLess` interpret the input string at the current position as a numeric value and compare it with the given parameter.

It's not related to what you write to the current output.

---

<div class="post-metadata">

### Author: ![stevehero](https://community.mp3tag.de/user_avatar/community.mp3tag.de/stevehero/32/337_2.png) [@stevehero](https://community.mp3tag.de/u/stevehero)
#### Post date: [July 16, 2023, 11:04am UTC](https://community.mp3tag.de/t/ifless-and-ifgreater-not-parsing-the-whole-output/61569/5 "2023-07-16T11:04:50Z")

</div>

Thanks for the explanation.

How would I go about checking the `track_count` value in the JSON structure?

I was trying:

```auto
OutputTo "_GREATER_THAN_CHECK" 
json_select "track_count"
IfGreater 1
Say "True"
Else
Say "False"
Endif

OutputTo "_LESS_THAN_CHECK" 
json_select "track_count"
IfLess 2
Say "True"
Else
Say "False"
Endif

```

But in a case where the `track_count` value is let's say 16. It returns true for both.

See here.

 ![image](https://community.mp3tag.de/uploads/default/original/2X/5/5c1a9b7936faf944efe5470b9f5fd792da20c0ec.png)

---

<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: [July 16, 2023, 11:39am UTC](https://community.mp3tag.de/t/ifless-and-ifgreater-not-parsing-the-whole-output/61569/6 "2023-07-16T11:39:44Z")

</div>

> [@stevehero](#):
>
> But in a case where the `track_count` value is let's say 16. It returns true for both.

Yes, this is to be expected from the code you've posted. Can you explain the intention behind those checks, i.e., what you're trying to achieve? It might help me to better understand the issue and propose an alternative approach.

---

<div class="post-metadata">

### Author: ![stevehero](https://community.mp3tag.de/user_avatar/community.mp3tag.de/stevehero/32/337_2.png) [@stevehero](https://community.mp3tag.de/u/stevehero)
#### Post date: [July 16, 2023, 11:49am UTC](https://community.mp3tag.de/t/ifless-and-ifgreater-not-parsing-the-whole-output/61569/7 "2023-07-16T11:49:20Z")

</div>

I basically want to check the value when using the `json_select` to check this value and then do an `IfLess` or `IfGreater` fn on that.

Here's the workaround that I'm using currently to only output to the `_TIME_CHEK` tag if the `track_count` is `1`.

```auto
OutputTo "_TIME_CHECK" # Shows track length when only single track available, convenient to check time comparison
json_select "track_count"
RegexpReplace "^\s*1\s*$" "True"
If "True"
json_unselect_object # Unselect data object
json_unselect_object # Unselect state object
json_unselect_object # Unselect "queries" 1 array (Album info)
json_select_array "queries" 2 # Select "queries" 2 array (The Tracks)
json_select_object "state"
json_select_object "data"
json_select_array "results" 1
json_select "length" # All that to get this little blighter
SayRest
json_unselect_object # Unselect results array
json_unselect_object # Unselect data object
json_unselect_object # Unselect state object
json_unselect_object # Unselect "queries" 2 array (The Tracks)
json_select_array "queries" 1 # Select "queries" 1 array (Album info)
json_select_object "state"
json_select_object "data"
Endif

```

---

<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: [July 16, 2023, 6:21pm UTC](https://community.mp3tag.de/t/ifless-and-ifgreater-not-parsing-the-whole-output/61569/8 "2023-07-16T18:21:11Z")

</div>

> [@stevehero](#):
>
> Here's the workaround that I'm using currently to only output to the `_TIME_CHEK` tag if the `track_count` is `1`.

Could you just do:

```plaintext
json_select "track_count"
If "1"
  json_unselect_object # Unselect data object
  ...
  SayRest
  ...
  json_select_object "data"
Endif

```

?

---

<div class="post-metadata">

### Author: ![stevehero](https://community.mp3tag.de/user_avatar/community.mp3tag.de/stevehero/32/337_2.png) [@stevehero](https://community.mp3tag.de/u/stevehero)
#### Post date: [July 16, 2023, 6:45pm UTC](https://community.mp3tag.de/t/ifless-and-ifgreater-not-parsing-the-whole-output/61569/9 "2023-07-16T18:45:46Z")

</div>

I did try that also Florian.

If `json_select "track_count"` returns `11,12,13,14,15,16,17,18 or 19`

Then:

`If "1"`

will equal true.

---

<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: [July 16, 2023, 6:50pm UTC](https://community.mp3tag.de/t/ifless-and-ifgreater-not-parsing-the-whole-output/61569/10 "2023-07-16T18:50:34Z")

</div>

Yes, true 🤦‍♂️

So `IfLess 2` would detect the track count = 1. Can you explain the purpose of `IfGreater 1` in your example? Still trying to find out what you're trying to achieve.

---

<div class="post-metadata">

### Author: ![stevehero](https://community.mp3tag.de/user_avatar/community.mp3tag.de/stevehero/32/337_2.png) [@stevehero](https://community.mp3tag.de/u/stevehero)
#### Post date: [July 16, 2023, 7:00pm UTC](https://community.mp3tag.de/t/ifless-and-ifgreater-not-parsing-the-whole-output/61569/11 "2023-07-16T19:00:53Z")

</div>

`IfLess 2` doesn't work either. Not for `21-29`.

`IfLess` or `IfGreater` doesn't seem to get the whole parsed number which isn't ideal when your wanting to know if the `track_count` value is greater than `1` when it returns true for the cases I've mentioned.

Basically, I was wanting to write to a tag if and only if the `track_count` value is `1`.

**I have worked around this by doing:**

```auto
OutputTo "_TIME_CHECK" # Shows track length when only single track available, convenient to check time comparison
json_select "track_count"
RegexpReplace "^\s*1\s*$" "True"
If "True"
json_select "length"
SayRest
Endif

```

But I was trying to get my head around the `IfLess` and `IfGreater` fns'.

---

<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: [July 19, 2023, 8:48pm UTC](https://community.mp3tag.de/t/ifless-and-ifgreater-not-parsing-the-whole-output/61569/12 "2023-07-19T20:48:47Z")

</div>

This is now fixed with [Mp3tag v3.21b](https://community.mp3tag.de/t/455).
