# How can I sort JSON by ID?

**URL:** https://discourse.processing.org/t/how-can-i-sort-json-by-id/15924
**Category:** Coding Questions
**Created:** [November 28, 2019, 8:57pm UTC](https://discourse.processing.org/t/how-can-i-sort-json-by-id/15924 "2019-11-28T20:57:09Z")
**Posts on this page:** 1
**Showing post:** 9

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [December 3, 2019, 2:43pm UTC](https://discourse.processing.org/t/how-can-i-sort-json-by-id/15924/9 "2019-12-03T14:43:30Z")

</div>

Solved

(I sorted a more simple ArrayList `toolTimers` first instead of sorting the JSON. )

```auto

import java.util.Collections; 
import java.util.Comparator;  

...

// vars for measuring Time (Space Bar and e)
ArrayList<ToolTimer> toolTimers = new ArrayList<ToolTimer>(); 

.....
  // this sorts 
  Collections.sort(toolTimers, new TimerComparator());

....

class TimerComparator implements Comparator<ToolTimer> {
  @Override
    public int compare (ToolTimer a, ToolTimer b) {

    if (a.timeArticleIndex.equals("") )
      println("equals ++++++++++++++++++++++++");

    //if a<b return -1;
    //if a==b return 0;
    //else return 1; 
    //return a.timeArticleIndex < b.timeArticleIndex ? -1 : 
    // a.timeArticleIndex == b.timeArticleIndex ? 0 :
    // 1;

    return a.timeArticleIndex.compareToIgnoreCase( b.timeArticleIndex);
  }
}//class

```

---

_[View the full topic](https://discourse.processing.org/t/how-can-i-sort-json-by-id/15924)._
