<p>Good question Xavier! I had a similar job recently, here's how I did it.</p>

<p>First I would suggest re-working your json file to be a little easier to parse. For example (hopefully I got your intention correctly):</p>

<pre><code>{
    "slider1": {
        "start": 1000,
        "end": 2000,
        "duration": 4,
        "ID": 1
    }
}
</code></pre>

<p>Then add two sliders to your layer, one called <code>Anim Duration (seconds)</code> with a default value of 4. If you want to read this value from the json file add the following expression instead:</p>

<pre><code>var data = footage("example.json").sourceData;

data.slider1.duration
</code></pre>

<p>Okay now to the second slider (which is the one that actually animates) add the following expression:</p>

<pre><code>var data = footage("example.json").sourceData;

start_value = data.slider1.start;
end_value = data.slider1.end;

step = (end_value - start_value) / effect("Anim Duration (seconds)")("Slider").value; // alternately you can just plug data.slider1.duration here instead of using a second slider...
count = Math.floor(step * (time - thisLayer.inPoint)); // you don't need to use the in-point here, but it is conventient if you know that's where you want to start your animation

if (count &lt; e_value) {
    count;
} else {
    end_value;
}
</code></pre>

<p>(if you have any trouble with this let me know, I don't have AE handy for testing so this was mainly done from memory and a snipped I have on me...)</p>

CC BY-SA 4.0
2019-02-10T23:39:27.197Z
2019-02-10T23:39:27.197Z
Spencer
<p>So let me explain, I have a json file with numbers and the duration of how long each number should be displayed which is 4 seconds.
I want the slider to show the first number (which is 1,000) and then four seconds later display 2,000 (which is second number) . But have it showing all the numbers in between 1,000-2,000.</p>

<p>My array looks like this:</p>

<pre><code>[
{ 
    "ID": 1,
    "slider": 1000,
    "duration": .4
},
{ 
    "ID": 2,
    "slider": 2000,
    "duration": .4
},
{ 
    "ID": 3,
    "slider": 3828.52,
    "duration": .4
}
]
</code></pre>

<p>And I have found a code that works, it starts at 0 seconds and animates 1,000 counting up to 2,000. The only problem with this code is that it has a delay, So when the animation starts it stays at 1,000 for about one whole second and then starts to animate counting up to 2,000 at the four second mark. Then same thing at the four second mark, it stays at 2,000 for a second and then animates. How do i prevent this delay? I would like it to be constant. Here is the code which works but causes the numbers to delay:</p>

<p><code>data = footage("example.json").sourceData;
rampTime = 3;
done = false;
i = t = tPrev = 0;
while (t &lt;= time){
  tPrev = t;
  t += rampTime + parseFloat(data[i].duration)/ .4;
  i++;
  if (i &gt;= data.length){
    done = true;
    break;
  }
}
if (done){
  parseFloat(data[data.length-1].slider);
}else{
  if ((time - tPrev) &lt; parseFloat(data[i-1].duration)/ .4){
    parseFloat(data[i-1].slider);
  }else{
    v1 = parseFloat(data[i-1].slider);
    v2 = parseFloat(data[i].slider);
    t1 = parseFloat(data[i-1].duration)/ .4;
    t2 = t1 + rampTime;
    linear(time-tPrev,t1,t2,v1,v2);
  }
}</code></p>

<p>If you can help find the solution please explain to me i am very new to coding and this is pretty complicated to me.Thank you!</p>

<after-effects><after-effects-expressions><after-effects-scripting>
Animate a Slider With Json File Import?
xavier gonzales
# Animate a Slider With Json File Import?

(Asked by: username_0 on 2019-02-09)

So let me explain, I have a json file with numbers and the duration of how long each number should be displayed which is 4 seconds.
I want the slider to show the first number (which is 1,000) and then four seconds later display 2,000 (which is second number) . But have it showing all the numbers in between 1,000-2,000.
My array looks like this:
[
{ 
    "ID": 1,
    "slider": 1000,
    "duration": .4
},
{ 
    "ID": 2,
    "slider": 2000,
    "duration": .4
},
{ 
    "ID": 3,
    "slider": 3828.52,
    "duration": .4
}
]

And I have found a code that works, it starts at 0 seconds and animates 1,000 counting up to 2,000. The only problem with this code is that it has a delay, So when the animation starts it stays at 1,000 for about one whole second and then starts to animate counting up to 2,000 at the four second mark. Then same thing at the four second mark, it stays at 2,000 for a second and then animates. How do i prevent this delay? I would like it to be constant. Here is the code which works but causes the numbers to delay:
data = footage("example.json").sourceData;
rampTime = 3;
done = false;
i = t = tPrev = 0;
while (t <= time){
  tPrev = t;
  t += rampTime + parseFloat(data[i].duration)/ .4;
  i++;
  if (i >= data.length){
    done = true;
    break;
  }
}
if (done){
  parseFloat(data[data.length-1].slider);
}else{
  if ((time - tPrev) < parseFloat(data[i-1].duration)/ .4){
    parseFloat(data[i-1].slider);
  }else{
    v1 = parseFloat(data[i-1].slider);
    v2 = parseFloat(data[i].slider);
    t1 = parseFloat(data[i-1].duration)/ .4;
    t2 = t1 + rampTime;
    linear(time-tPrev,t1,t2,v1,v2);
  }
}
If you can help find the solution please explain to me i am very new to coding and this is pretty complicated to me.Thank you!

**Tags:** after-effects, after-effects-expressions, after-effects-scripting


---

## 1 answers

### Answer by username_1 on 2019-02-10. Score: 1

Good question Xavier! I had a similar job recently, here's how I did it.
First I would suggest re-working your json file to be a little easier to parse. For example (hopefully I got your intention correctly):
{
    "slider1": {
        "start": 1000,
        "end": 2000,
        "duration": 4,
        "ID": 1
    }
}

Then add two sliders to your layer, one called Anim Duration (seconds) with a default value of 4. If you want to read this value from the json file add the following expression instead:
var data = footage("example.json").sourceData;

data.slider1.duration

Okay now to the second slider (which is the one that actually animates) add the following expression:
var data = footage("example.json").sourceData;

start_value = data.slider1.start;
end_value = data.slider1.end;

step = (end_value - start_value) / effect("Anim Duration (seconds)")("Slider").value; // alternately you can just plug data.slider1.duration here instead of using a second slider...
count = Math.floor(step * (time - thisLayer.inPoint)); // you don't need to use the in-point here, but it is conventient if you know that's where you want to start your animation

if (count < e_value) {
    count;
} else {
    end_value;
}

(if you have any trouble with this let me know, I don't have AE handy for testing so this was mainly done from memory and a snipped I have on me...)


---

