Lego2012
9/7/2017 - 3:50 PM

Range last n entries of JSON data file

Range last n entries of JSON data file

The main lessons I learnt:

Loading a JSON file into a variable makes things easier. By this I can already apply conditions (display only those with “permissionPub” = “yes”) first and last can be easily applied as function to a range sort command. In the first post this would already have been possible in line 2 but then the condition wasn’t working as I wanted

{{ $json := getJSON "data/signatures/signatures.json" }}
{{ $json := where $json "permissionPub" "yes" }}

{{ range sort $json "timestamp" "desc" | first 10 }}
   <tr>
      <td>{{ .name }}</td>
   </tr>
{{ end }}

{{ $json := getJSON "data/signatures/signatures.json" }}
{{ $json := where $json "permissionPub" "yes" }}

{{ range sort $json "timestamp" "desc" | first 10 }}
   <tr>
      <td>{{ .name }}</td>
   </tr>
{{ end }}