-3

I am trying to sort this json object according to "x" but can't find any solution.

{
    "resources": [, {
        "urlC": "https://example.com/ghi.png",
        "size": 1657,
        "x": 610026.970856,
        "y": 2,
        "x2": 610026.970874,
        "status": 200
    },{
        "urlC": "https://example.com/abc.png",
        "size": 1827,
        "x": 610026.970777,
        "y": 0,
        "x2": 610026.970795,
        "status": 200
    }, {
        "urlC": "https://example.com/def.png",
        "size": 2026,
        "x": 610026.970816,
        "y": 1,
        "x2": 610026.970835,
        "status": 200
    }, {
        "urlC": "https://example.com/jkl.png",
        "size": 1871,
        "x": 610026.970897,
        "y": 3,
        "x2": 610026.970914,
        "status": 200
    }]
}

I want this type of data :

{
"resources": [{
    "urlC": "https://example.com/abc.png",
    "size": 1827,
    "x": 610026.970777,
    "y": 0,
    "x2": 610026.970795,
    "status": 200
}, {
    "urlC": "https://example.com/def.png",
    "size": 2026,
    "x": 610026.970816,
    "y": 1,
    "x2": 610026.970835,
    "status": 200
}, {
    "urlC": "https://example.com/ghi.png",
    "size": 1657,
    "x": 610026.970856,
    "y": 2,
    "x2": 610026.970874,
    "status": 200
}, {
    "urlC": "https://example.com/jkl.png",
    "size": 1871,
    "x": 610026.970897,
    "y": 3,
    "x2": 610026.970914,
    "status": 200
}]}
talex
  • 17,973
  • 3
  • 29
  • 66
amit lodhi
  • 11
  • 4

1 Answers1

0

I suggest you an alternative way which you can do it by yourself.

Step-1: convert the json into java object.

step-2: then sort the array based on "x" using comparator interface.

step-2: Again convert java object into json string

Kanahaiya
  • 406
  • 2
  • 11