1

I am facing the problem in generic extract object fixture .

My service layer provides me Json something like this. It is an array/list of values

[{"id":1,"description":"Anti-takeover Provision"},
{"id":2,"description":"Capital Structure"},  
{"id":3,"description":"Director"},
{"id":4,"description":"Equity Plan"},
{"id":5,"description":"Executive Compensation"},
{"id":6,"description":"General Governance"},
{"id":7,"description":"Merger or Acquisition"},
{"id":12,"description":"Other"},
{"id":8,"description":"Proxy Contest"},
{"id":9,"description":"Reincorporation"},
{"id":10,"description":"Shareholder Proposal"},
{"id":11,"description":"Shareholder Rights"}]

But my database json

{"document":[{"VALUE":"Anti-takeover Provision","TOPIC_ID":1},
{"VALUE":"Capital Structure","TOPIC_ID":2},
{"VALUE":"Director","TOPIC_ID":3},
{"VALUE":"Equity Plan","TOPIC_ID":4},
{"VALUE":"Executive Compensation","TOPIC_ID":5},
{"VALUE":"General Governance","TOPIC_ID":6},
{"VALUE":"Merger or Acquisition","TOPIC_ID":7},
{"VALUE":"Other","TOPIC_ID":12},
{"VALUE":"Proxy Contest","TOPIC_ID":8},
{"VALUE":"Reincorporation","TOPIC_ID":9},
{"VALUE":"Shareholder Proposal","TOPIC_ID":10},
{"VALUE":"Shareholder Rights","TOPIC_ID":11}]}

How do i compare these two values easily?

J. Chomel
  • 8,193
  • 15
  • 41
  • 69
Sujay66
  • 103
  • 1
  • 11

1 Answers1

0
  1. Check that the lengths are the same

  2. Sort the two lists by their corresponding ID fields

  3. Check that the values match

    // stop as soon as you find a difference
    
    for(i=0; i < listLength; i++) {
    
        if (listA[i].id != listB[i].TOPIC_ID) { return false; }
    
        if (listA[i].description != listB[i].VALUE) { return false; }
    }
    
    // if you get here, they must be the same
    
    return true;
    
Community
  • 1
  • 1
Bob Salmon
  • 411
  • 4
  • 10