liufengyun / hashdiff

Hashdiff is a ruby library to to compute the smallest difference between two hashes

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

JSON data comparison failed when it has array of JSON data

kotubhaskar opened this issue · comments

xml_doc = Nokogiri::XML(response.body)
input_hash = Hash.from_xml(xml.to_s)
puts input_hash
puts "*" * 120
response_hash = Hash.from_xml(Nokogiri::XML(response.body).to_s)
puts response_hash.to_json

And I am sending input hash and response hash for diff = HashDiff.best_diffinput_hash, response_hash)

I am seeing that even there are elements present I could not get them compared

here I am giving input JSON and response JSON

JSON_1

{"requisition_header":{"requested_by":{"login":"coupasupport"},"department":{"name":"Marketing"},"pcard":null,"ship_to_address":{"name":"Address_1435124879"},"justification":null,"attachments":[],"requisition_lines":[{"item":{"name":"RISC Server with 4 CPU and 16Gb RAM"},"line_num":1,"need_by_date":"2010-09-23T07:00:00.000Z","account":{"code":"SF-Marketing-Indirect","account_type":{"name":"Ace Corporate"}}}]}}

JSON_2

{"requisition_header":{"id":5545,"created_at":"2015-06-24T05:48:19.000Z","updated_at":"2015-06-24T05:48:19.000Z","buyer_note":null,"justification":null,"need_by_date":null,"reject_reason_comment":null,"status":"draft","submitted_at":null,"exported":false,"ship_to_attention":"Coupa Support","total":"2049.0","mobile_total":"2049.0","custom_field_4":null,"custom_field_3":null,"zcust":null,"custom_field_1":null,"currency":{"id":1,"code":"USD","updated_by":{"id":1528,"login":"test","email":"test@test.com","employee_number":null,"firstname":"test","lastname":"key","salesforce_id":null,"custom_field_12":null,"custom_field_11":null,"date":null,"dropdown":null,"radio":null,"custom_field_8":null,"bussiness_unit":null,"purchase":null,"custom_field_3":null,"number_oksana":null,"gpo_entity":null}},"department":{"id":1,"created_at":"2008-10-27T20:00:48.000Z","updated_at":"2015-05-15T12:35:14.000Z","name":"Marketing","active":true,"created_by":{"id":1,"login":"coupasupport","email":"upgrade+coupasupport@coupa.com","employee_number":null,"firstname":"Coupa","lastname":"Support","salesforce_id":null,"custom_field_12":null,"custom_field_11":null,"date":null,"dropdown":null,"radio":null,"custom_field_8":null,"bussiness_unit":null,"purchase":null,"custom_field_3":null,"number_oksana":null,"gpo_entity":null},"updated_by":{"id":494,"login":"bhaskar","email":"bhaskar@example.com","employee_number":null,"firstname":"Bhaskar","lastname":"K","salesforce_id":null,"custom_field_12":null,"custom_field_11":null,"date":null,"dropdown":null,"radio":null,"custom_field_8":null,"bussiness_unit":null,"purchase":null,"custom_field_3":null,"number_oksana":null,"gpo_entity":null}},"requested_by":{"id":1,"login":"coupasupport","email":"upgrade+coupasupport@coupa.com","employee_number":null,"firstname":"Coupa","lastname":"Support","salesforce_id":null,"custom_field_12":null,"custom_field_11":null,"date":null,"dropdown":null,"radio":null,"custom_field_8":null,"bussiness_unit":null,"purchase":null,"custom_field_3":null,"number_oksana":null,"gpo_entity":null},"ship_to_address":{"id":31420,"created_at":"2015-06-24T05:48:16.000Z","updated_at":"2015-06-24T05:48:16.000Z","name":"Address_1435124879","location_code":null,"street1":"2 W 5th Ave","street2":"Suite 300","city":"San Mateo","state":"CA","postal_code":"94404","attention":null,"active":true,"business_group_name":"Everyone","vat_number":null,"country":{"id":223,"code":"US","name":"United States"},"created_by":{"id":494,"login":"bhaskar","email":"bhaskar@example.com","employee_number":null,"firstname":"Bhaskar","lastname":"K","salesforce_id":null,"custom_field_12":null,"custom_field_11":null,"date":null,"dropdown":null,"radio":null,"custom_field_8":null,"bussiness_unit":null,"purchase":null,"custom_field_3":null,"number_oksana":null,"gpo_entity":null},"updated_by":{"id":494,"login":"bhaskar","email":"bhaskar@example.com","employee_number":null,"firstname":"Bhaskar","lastname":"K","salesforce_id":null,"custom_field_12":null,"custom_field_11":null,"date":null,"dropdown":null,"radio":null,"custom_field_8":null,"bussiness_unit":null,"purchase":null,"custom_field_3":null,"number_oksana":null,"gpo_entity":null}},"attachments":[],"requisition_lines":[{"id":8782,"created_at":"2015-06-24T05:48:19.000Z","updated_at":"2015-06-24T05:48:19.000Z","description":"RISC Server with 4 CPU and 16Gb RAM","line_num":1,"need_by_date":"2010-09-23T07:00:00.000Z","order_line_id":null,"receipt_required":null,"source_part_num":null,"status":null,"sub_line_num":null,"supp_aux_part_num":null,"total":"2049.0","source_type":"Catalog Item","line_type":"RequisitionAmountLine","unit_price":"2049.0","prepaid":null,"custom_field_5":null,"cf1":null,"custom_field_4":null,"user_1":null,"account":{"id":13,"created_at":"2008-10-27T20:20:36.000Z","updated_at":"2015-06-24T05:42:40.000Z","name":"San Francisco - Marketing, Indirect","code":"SF-Marketing-Indirect","active":true,"segment_1":"SF","segment_2":"Marketing","segment_3":"Indirect","segment_4":null,"segment_5":null,"segment_6":null,"segment_7":null,"segment_8":null,"segment_9":null,"segment_10":null,"segment_11":null,"segment_12":null,"segment_13":null,"segment_14":null,"segment_15":null,"segment_16":null,"segment_17":null,"segment_18":null,"segment_19":null,"segment_20":null,"account_type":{"id":1,"created_at":"2008-10-27T20:10:01.000Z","updated_at":"2015-06-18T08:06:26.000Z","name":"Ace Corporate","active":true,"currency":{"id":1,"code":"USD","updated_by":{"id":1528,"login":"test","email":"test@test.com","employee_number":null,"firstname":"test","lastname":"key","salesforce_id":null,"custom_field_12":null,"custom_field_11":null,"date":null,"dropdown":null,"radio":null,"custom_field_8":null,"bussiness_unit":null,"purchase":null,"custom_field_3":null,"number_oksana":null,"gpo_entity":null}},"primary_contact":{"id":14,"created_at":"2008-10-27T20:10:01.000Z","updated_at":"2015-05-14T06:40:12.000Z","email":"harinni.coupa01+123@gmail.com","name_prefix":null,"name_suffix":null,"name_additional":null,"name_given":"xxx","name_family":"yyy","name_fullname":null,"notes":null,"created_by":{"id":1,"login":"coupasupport","email":"upgrade+coupasupport@coupa.com","employee_number":null,"firstname":"Coupa","lastname":"Support","salesforce_id":null,"custom_field_12":null,"custom_field_11":null,"date":null,"dropdown":null,"radio":null,"custom_field_8":null,"bussiness_unit":null,"purchase":null,"custom_field_3":null,"number_oksana":null,"gpo_entity":null},"updated_by":{"id":1,"login":"coupasupport","email":"upgrade+coupasupport@coupa.com","employee_number":null,"firstname":"Coupa","lastname":"Support","salesforce_id":null,"custom_field_12":null,"custom_field_11":null,"date":null,"dropdown":null,"radio":null,"custom_field_8":null,"bussiness_unit":null,"purchase":null,"custom_field_3":null,"number_oksana":null,"gpo_entity":null}},"primary_address":{"id":31075,"created_at":"2008-10-27T20:10:01.000Z","updated_at":"2015-05-14T06:40:12.000Z","name":"test address name","location_code":null,"street1":"Line1","street2":"Line2","city":"City","state":"State","postal_code":"151515","attention":null,"active":true,"business_group_name":null,"vat_number":null,"country":{"id":22,"code":"BE","name":"Belgium"},"vat_country":{"id":22,"code":"BE","name":"Belgium"},"created_by":{"id":1,"login":"coupasupport","email":"upgrade+coupasupport@coupa.com","employee_number":null,"firstname":"Coupa","lastname":"Support","salesforce_id":null,"custom_field_12":null,"custom_field_11":null,"date":null,"dropdown":null,"radio":null,"custom_field_8":null,"bussiness_unit":null,"purchase":null,"custom_field_3":null,"number_oksana":null,"gpo_entity":null},"updated_by":{"id":1,"login":"coupasupport","email":"upgrade+coupasupport@coupa.com","employee_number":null,"firstname":"Coupa","lastname":"Support","salesforce_id":null,"custom_field_12":null,"custom_field_11":null,"date":null,"dropdown":null,"radio":null,"custom_field_8":null,"bussiness_unit":null,"purchase":null,"custom_field_3":null,"number_oksana":null,"gpo_entity":null}},"created_by":{"id":1,"login":"coupasupport","email":"upgrade+coupasupport@coupa.com","employee_number":null,"firstname":"Coupa","lastname":"Support","salesforce_id":null,"custom_field_12":null,"custom_field_11":null,"date":null,"dropdown":null,"radio":null,"custom_field_8":null,"bussiness_unit":null,"purchase":null,"custom_field_3":null,"number_oksana":null,"gpo_entity":null},"updated_by":{"id":1528,"login":"test","email":"test@test.com","employee_number":null,"firstname":"test","lastname":"key","salesforce_id":null,"custom_field_12":null,"custom_field_11":null,"date":null,"dropdown":null,"radio":null,"custom_field_8":null,"bussiness_unit":null,"purchase":null,"custom_field_3":null,"number_oksana":null,"gpo_entity":null}},"created_by":{"id":1,"login":"coupasupport","email":"upgrade+coupasupport@coupa.com","employee_number":null,"firstname":"Coupa","lastname":"Support","salesforce_id":null,"custom_field_12":null,"custom_field_11":null,"date":null,"dropdown":null,"radio":null,"custom_field_8":null,"bussiness_unit":null,"purchase":null,"custom_field_3":null,"number_oksana":null,"gpo_entity":null},"updated_by":{"id":494,"login":"bhaskar","email":"bhaskar@example.com","employee_number":null,"firstname":"Bhaskar","lastname":"K","salesforce_id":null,"custom_field_12":null,"custom_field_11":null,"date":null,"dropdown":null,"radio":null,"custom_field_8":null,"bussiness_unit":null,"purchase":null,"custom_field_3":null,"number_oksana":null,"gpo_entity":null}},"account_allocations":[],"item":{"id":230,"created_at":"2012-12-12T21:40:06.000Z","updated_at":"2015-06-24T05:44:30.000Z","description":"The minimum requirement for this bid is:A blade enclosure cost (to include all components for it to work).A server blade to the minimum specification: 2 x 72GB Hard Disk; 2 x 100mbps Ethernet ports.The server blade (preferable) or the blade enclosure must have a slot for either a 1GB Ethernet card with 2 ports or a fibre Channel (HBA) with 2 ports.The cost of the blade enclosure and server blade must include 1 years maintenance to the level indicated in the RFP.The optional cost for years 2 and 3 maintenance is to the level indicated in the RFP.The installation services cost must include, un-boxing of the product, complete installation to agreed standards, removal of boxes from site.","item_number":null,"name":"RISC Server with 4 CPU and 16Gb RAM","active":false,"storage_quantity":null,"consumption_quantity":null,"field":null,"commodity":{"id":10,"created_at":"2011-04-12T16:28:24.000Z","updated_at":"2011-04-12T21:58:19.000Z","active":true,"name":"Hardware","com_man":null,"custom_field_4":null,"custom_field_3":null,"gl_code":null,"acct":"Assets","parent":{"id":2,"created_at":"2008-10-27T20:04:00.000Z","updated_at":"2015-05-14T05:57:46.000Z","active":true,"name":"IT","com_man":null,"custom_field_4":null,"custom_field_3":null,"gl_code":null,"acct":"Indirect","created_by":{"id":1,"login":"coupasupport","email":"upgrade+coupasupport@coupa.com","employee_number":null,"firstname":"Coupa","lastname":"Support","salesforce_id":null,"custom_field_12":null,"custom_field_11":null,"date":null,"dropdown":null,"radio":null,"custom_field_8":null,"bussiness_unit":null,"purchase":null,"custom_field_3":null,"number_oksana":null,"gpo_entity":null},"updated_by":{"id":494,"login":"bhaskar","email":"bhaskar@example.com","employee_number":null,"firstname":"Bhaskar","lastname":"K","salesforce_id":null,"custom_field_12":null,"custom_field_11":null,"date":null,"dropdown":null,"radio":null,"custom_field_8":null,"bussiness_unit":null,"purchase":null,"custom_field_3":null,"number_oksana":null,"gpo_entity":null}},"created_by":{"id":16,"login":"krhine","email":"kevin.rhine@coupa.com","employee_number":null,"firstname":"Kevin","lastname":"Rhine","salesforce_id":null,"custom_field_12":null,"custom_field_11":null,"date":null,"dropdown":null,"radio":null,"custom_field_8":null,"bussiness_unit":null,"purchase":null,"custom_field_3":null,"number_oksana":null,"gpo_entity":null},"updated_by":{"id":1,"login":"coupasupport","email":"upgrade+coupasupport@coupa.com","employee_number":null,"firstname":"Coupa","lastname":"Support","salesforce_id":null,"custom_field_12":null,"custom_field_11":null,"date":null,"dropdown":null,"radio":null,"custom_field_8":null,"bussiness_unit":null,"purchase":null,"custom_field_3":null,"number_oksana":null,"gpo_entity":null}},"uom":{"id":1,"created_at":null,"updated_at":"2015-06-18T08:06:27.000Z","code":"EA","name":"Each","allowable_precision":0,"active":true,"updated_by":{"id":1528,"login":"test","email":"test@test.com","employee_number":null,"firstname":"test","lastname":"key","salesforce_id":null,"custom_field_12":null,"custom_field_11":null,"date":null,"dropdown":null,"radio":null,"custom_field_8":null,"bussiness_unit":null,"purchase":null,"custom_field_3":null,"number_oksana":null,"gpo_entity":null}},"reorder_alerts":[],"created_by":{"id":1,"login":"coupasupport","email":"upgrade+coupasupport@coupa.com","employee_number":null,"firstname":"Coupa","lastname":"Support","salesforce_id":null,"custom_field_12":null,"custom_field_11":null,"date":null,"dropdown":null,"radio":null,"custom_field_8":null,"bussiness_unit":null,"purchase":null,"custom_field_3":null,"number_oksana":null,"gpo_entity":null},"updated_by":{"id":494,"login":"bhaskar","email":"bhaskar@example.com","employee_number":null,"firstname":"Bhaskar","lastname":"K","salesforce_id":null,"custom_field_12":null,"custom_field_11":null,"date":null,"dropdown":null,"radio":null,"custom_field_8":null,"bussiness_unit":null,"purchase":null,"custom_field_3":null,"number_oksana":null,"gpo_entity":null}},"currency":{"id":1,"code":"USD","updated_by":{"id":1528,"login":"test","email":"test@test.com","employee_number":null,"firstname":"test","lastname":"key","salesforce_id":null,"custom_field_12":null,"custom_field_11":null,"date":null,"dropdown":null,"radio":null,"custom_field_8":null,"bussiness_unit":null,"purchase":null,"custom_field_3":null,"number_oksana":null,"gpo_entity":null}},"payment_term":{"id":1,"created_at":null,"updated_at":"2015-06-16T07:23:04.000Z","code":"Net 30","description":null,"days_for_net_payment":2,"days_for_discount_payment":null,"discount_rate":null,"active":true,"content_groups":[{"id":1,"created_at":"2006-08-28T02:40:04.000Z","updated_at":"2015-06-17T09:43:58.000Z","name":"Everyone","description":"All users can see documents assigned to this group","updated_by":{"id":494,"login":"bhaskar","email":"bhaskar@example.com","employee_number":null,"firstname":"Bhaskar","lastname":"K","salesforce_id":null,"custom_field_12":null,"custom_field_11":null,"date":null,"dropdown":null,"radio":null,"custom_field_8":null,"bussiness_unit":null,"purchase":null,"custom_field_3":null,"number_oksana":null,"gpo_entity":null}}],"updated_by":{"id":1528,"login":"test","email":"test@test.com","employee_number":null,"firstname":"test","lastname":"key","salesforce_id":null,"custom_field_12":null,"custom_field_11":null,"date":null,"dropdown":null,"radio":null,"custom_field_8":null,"bussiness_unit":null,"purchase":null,"custom_field_3":null,"number_oksana":null,"gpo_entity":null}},"shipping_term":{"id":1,"created_at":null,"updated_at":"2015-05-15T06:27:25.000Z","code":"Standard","description":null,"active":true,"content_groups":[{"id":1,"created_at":"2006-08-28T02:40:04.000Z","updated_at":"2015-06-17T09:43:58.000Z","name":"Everyone","description":"All users can see documents assigned to this group","updated_by":{"id":494,"login":"bhaskar","email":"bhaskar@example.com","employee_number":null,"firstname":"Bhaskar","lastname":"K","salesforce_id":null,"custom_field_12":null,"custom_field_11":null,"date":null,"dropdown":null,"radio":null,"custom_field_8":null,"bussiness_unit":null,"purchase":null,"custom_field_3":null,"number_oksana":null,"gpo_entity":null}}],"updated_by":{"id":494,"login":"bhaskar","email":"bhaskar@example.com","employee_number":null,"firstname":"Bhaskar","lastname":"K","salesforce_id":null,"custom_field_12":null,"custom_field_11":null,"date":null,"dropdown":null,"radio":null,"custom_field_8":null,"bussiness_unit":null,"purchase":null,"custom_field_3":null,"number_oksana":null,"gpo_entity":null}},"asset_tags":[],"attachments":[],"created_by":{"id":494,"login":"bhaskar","email":"bhaskar@example.com","employee_number":null,"firstname":"Bhaskar","lastname":"K","salesforce_id":null,"custom_field_12":null,"custom_field_11":null,"date":null,"dropdown":null,"radio":null,"custom_field_8":null,"bussiness_unit":null,"purchase":null,"custom_field_3":null,"number_oksana":null,"gpo_entity":null},"updated_by":{"id":494,"login":"bhaskar","email":"bhaskar@example.com","employee_number":null,"firstname":"Bhaskar","lastname":"K","salesforce_id":null,"custom_field_12":null,"custom_field_11":null,"date":null,"dropdown":null,"radio":null,"custom_field_8":null,"bussiness_unit":null,"purchase":null,"custom_field_3":null,"number_oksana":null,"gpo_entity":null}}],"approvals":[],"created_by":{"id":494,"login":"bhaskar","email":"bhaskar@example.com","employee_number":null,"firstname":"Bhaskar","lastname":"K","salesforce_id":null,"custom_field_12":null,"custom_field_11":null,"date":null,"dropdown":null,"radio":null,"custom_field_8":null,"bussiness_unit":null,"purchase":null,"custom_field_3":null,"number_oksana":null,"gpo_entity":null},"updated_by":{"id":494,"login":"bhaskar","email":"bhaskar@example.com","employee_number":null,"firstname":"Bhaskar","lastname":"K","salesforce_id":null,"custom_field_12":null,"custom_field_11":null,"date":null,"dropdown":null,"radio":null,"custom_field_8":null,"bussiness_unit":null,"purchase":null,"custom_field_3":null,"number_oksana":null,"gpo_entity":null},"mobile_currency":{"id":1,"code":"USD","updated_by":{"id":1528,"login":"test","email":"test@test.com","employee_number":null,"firstname":"test","lastname":"key","salesforce_id":null,"custom_field_12":null,"custom_field_11":null,"date":null,"dropdown":null,"radio":null,"custom_field_8":null,"bussiness_unit":null,"purchase":null,"custom_field_3":null,"number_oksana":null,"gpo_entity":null}}}}

RESULT

-requisition_header.pcard
+requisition_header.requested_by.id1
+requisition_header.requested_by.emailupgrade+coupasupport@coupa.com
+requisition_header.requested_by.employee_number
+requisition_header.requested_by.firstnameCoupa
+requisition_header.requested_by.lastnameSupport
+requisition_header.requested_by.salesforce_id
+requisition_header.requested_by.custom_field_12
+requisition_header.requested_by.custom_field_11
+requisition_header.requested_by.date
+requisition_header.requested_by.dropdown
+requisition_header.requested_by.radio
+requisition_header.requested_by.custom_field_8
+requisition_header.requested_by.bussiness_unit
+requisition_header.requested_by.purchase
+requisition_header.requested_by.custom_field_3
+requisition_header.requested_by.number_oksana
+requisition_header.requested_by.gpo_entity
+requisition_header.department.id1
+requisition_header.department.created_at2008-10-27T20:00:48.000Z
+requisition_header.department.updated_at2015-05-15T12:35:14.000Z
+requisition_header.department.activetrue
+requisition_header.department.created_by{"id"=>1, "login"=>"coupasupport", "email"=>"upgrade+coupasupport@coupa.com", "employee_number"=>nil, "firstname"=>"Coupa", "lastname"=>"Support", "salesforce_id"=>nil, "custom_field_12"=>nil, "custom_field_11"=>nil, "date"=>nil, "dropdown"=>nil, "radio"=>nil, "custom_field_8"=>nil, "bussiness_unit"=>nil, "purchase"=>nil, "custom_field_3"=>nil, "number_oksana"=>nil, "gpo_entity"=>nil}
+requisition_header.department.updated_by{"id"=>494, "login"=>"bhaskar", "email"=>"bhaskar@example.com", "employee_number"=>nil, "firstname"=>"Bhaskar", "lastname"=>"K", "salesforce_id"=>nil, "custom_field_12"=>nil, "custom_field_11"=>nil, "date"=>nil, "dropdown"=>nil, "radio"=>nil, "custom_field_8"=>nil, "bussiness_unit"=>nil, "purchase"=>nil, "custom_field_3"=>nil, "number_oksana"=>nil, "gpo_entity"=>nil}
+requisition_header.ship_to_address.id31420
+requisition_header.ship_to_address.created_at2015-06-24T05:48:16.000Z
+requisition_header.ship_to_address.updated_at2015-06-24T05:48:16.000Z
+requisition_header.ship_to_address.location_code
+requisition_header.ship_to_address.street12 W 5th Ave
+requisition_header.ship_to_address.street2Suite 300
+requisition_header.ship_to_address.citySan Mateo
+requisition_header.ship_to_address.stateCA
+requisition_header.ship_to_address.postal_code94404
+requisition_header.ship_to_address.attention
+requisition_header.ship_to_address.activetrue
+requisition_header.ship_to_address.business_group_nameEveryone
+requisition_header.ship_to_address.vat_number
+requisition_header.ship_to_address.country{"id"=>223, "code"=>"US", "name"=>"United States"}
+requisition_header.ship_to_address.created_by{"id"=>494, "login"=>"bhaskar", "email"=>"bhaskar@example.com", "employee_number"=>nil, "firstname"=>"Bhaskar", "lastname"=>"K", "salesforce_id"=>nil, "custom_field_12"=>nil, "custom_field_11"=>nil, "date"=>nil, "dropdown"=>nil, "radio"=>nil, "custom_field_8"=>nil, "bussiness_unit"=>nil, "purchase"=>nil, "custom_field_3"=>nil, "number_oksana"=>nil, "gpo_entity"=>nil}
+requisition_header.ship_to_address.updated_by{"id"=>494, "login"=>"bhaskar", "email"=>"bhaskar@example.com", "employee_number"=>nil, "firstname"=>"Bhaskar", "lastname"=>"K", "salesforce_id"=>nil, "custom_field_12"=>nil, "custom_field_11"=>nil, "date"=>nil, "dropdown"=>nil, "radio"=>nil, "custom_field_8"=>nil, "bussiness_unit"=>nil, "purchase"=>nil, "custom_field_3"=>nil, "number_oksana"=>nil, "gpo_entity"=>nil}
-requisition_header.requisition_lines[0]{"item"=>{"name"=>"RISC Server with 4 CPU and 16Gb RAM"}, "line_num"=>1, "need_by_date"=>"2010-09-23T07:00:00.000Z", "account"=>{"code"=>"SF-Marketing-Indirect", "account_type"=>{"name"=>"Ace Corporate"}}}
+requisition_header.requisition_lines[0]{"id"=>8782, "created_at"=>"2015-06-24T05:48:19.000Z", "updated_at"=>"2015-06-24T05:48:19.000Z", "description"=>"RISC Server with 4 CPU and 16Gb RAM", "line_num"=>1, "need_by_date"=>"2010-09-23T07:00:00.000Z", "order_line_id"=>nil, "receipt_required"=>nil, "source_part_num"=>nil, "status"=>nil, "sub_line_num"=>nil, "supp_aux_part_num"=>nil, "total"=>"2049.0", "source_type"=>"Catalog Item", "line_type"=>"RequisitionAmountLine", "unit_price"=>"2049.0", "prepaid"=>nil, "custom_field_5"=>nil, "cf1"=>nil, "custom_field_4"=>nil, "user_1"=>nil, "account"=>{"id"=>13, "created_at"=>"2008-10-27T20:20:36.000Z", "updated_at"=>"2015-06-24T05:42:40.000Z", "name"=>"San Francisco - Marketing, Indirect", "code"=>"SF-Marketing-Indirect", "active"=>true, "segment_1"=>"SF", "segment_2"=>"Marketing", "segment_3"=>"Indirect", "segment_4"=>nil, "segment_5"=>nil, "segment_6"=>nil, "segment_7"=>nil, "segment_8"=>nil, "segment_9"=>nil, "segment_10"=>nil, "segment_11"=>nil, "segment_12"=>nil, "segment_13"=>nil, "segment_14"=>nil, "segment_15"=>nil, "segment_16"=>nil, "segment_17"=>nil, "segment_18"=>nil, "segment_19"=>nil, "segment_20"=>nil, "account_type"=>{"id"=>1, "created_at"=>"2008-10-27T20:10:01.000Z", "updated_at"=>"2015-06-18T08:06:26.000Z", "name"=>"Ace Corporate", "active"=>true, "currency"=>{"id"=>1, "code"=>"USD", "updated_by"=>{"id"=>1528, "login"=>"test", "email"=>"test@test.com", "employee_number"=>nil, "firstname"=>"test", "lastname"=>"key", "salesforce_id"=>nil, "custom_field_12"=>nil, "custom_field_11"=>nil, "date"=>nil, "dropdown"=>nil, "radio"=>nil, "custom_field_8"=>nil, "bussiness_unit"=>nil, "purchase"=>nil, "custom_field_3"=>nil, "number_oksana"=>nil, "gpo_entity"=>nil}}, "primary_contact"=>{"id"=>14, "created_at"=>"2008-10-27T20:10:01.000Z", "updated_at"=>"2015-05-14T06:40:12.000Z", "email"=>"harinni.coupa01+123@gmail.com", "name_prefix"=>nil, "name_suffix"=>nil, "name_additional"=>nil, "name_given"=>"xxx", "name_family"=>"yyy", "name_fullname"=>nil, "notes"=>nil, "created_by"=>{"id"=>1, "login"=>"coupasupport", "email"=>"upgrade+coupasupport@coupa.com", "employee_number"=>nil, "firstname"=>"Coupa", "lastname"=>"Support", "salesforce_id"=>nil, "custom_field_12"=>nil, "custom_field_11"=>nil, "date"=>nil, "dropdown"=>nil, "radio"=>nil, "custom_field_8"=>nil, "bussiness_unit"=>nil, "purchase"=>nil, "custom_field_3"=>nil, "number_oksana"=>nil, "gpo_entity"=>nil}, "updated_by"=>{"id"=>1, "login"=>"coupasupport", "email"=>"upgrade+coupasupport@coupa.com", "employee_number"=>nil, "firstname"=>"Coupa", "lastname"=>"Support", "salesforce_id"=>nil, "custom_field_12"=>nil, "custom_field_11"=>nil, "date"=>nil, "dropdown"=>nil, "radio"=>nil, "custom_field_8"=>nil, "bussiness_unit"=>nil, "purchase"=>nil, "custom_field_3"=>nil, "number_oksana"=>nil, "gpo_entity"=>nil}}, "primary_address"=>{"id"=>31075, "created_at"=>"2008-10-27T20:10:01.000Z", "updated_at"=>"2015-05-14T06:40:12.000Z", "name"=>"test address name", "location_code"=>nil, "street1"=>"Line1", "street2"=>"Line2", "city"=>"City", "state"=>"State", "postal_code"=>"151515", "attention"=>nil, "active"=>true, "business_group_name"=>nil, "vat_number"=>nil, "country"=>{"id"=>22, "code"=>"BE", "name"=>"Belgium"}, "vat_country"=>{"id"=>22, "code"=>"BE", "name"=>"Belgium"}, "created_by"=>{"id"=>1, "login"=>"coupasupport", "email"=>"upgrade+coupasupport@coupa.com", "employee_number"=>nil, "firstname"=>"Coupa", "lastname"=>"Support", "salesforce_id"=>nil, "custom_field_12"=>nil, "custom_field_11"=>nil, "date"=>nil, "dropdown"=>nil, "radio"=>nil, "custom_field_8"=>nil, "bussiness_unit"=>nil, "purchase"=>nil, "custom_field_3"=>nil, "number_oksana"=>nil, "gpo_entity"=>nil}, "updated_by"=>{"id"=>1, "login"=>"coupasupport", "email"=>"upgrade+coupasupport@coupa.com", "employee_number"=>nil, "firstname"=>"Coupa", "lastname"=>"Support", "salesforce_id"=>nil, "custom_field_12"=>nil, "custom_field_11"=>nil, "date"=>nil, "dropdown"=>nil, "radio"=>nil, "custom_field_8"=>nil, "bussiness_unit"=>nil, "purchase"=>nil, "custom_field_3"=>nil, "number_oksana"=>nil, "gpo_entity"=>nil}}, "created_by"=>{"id"=>1, "login"=>"coupasupport", "email"=>"upgrade+coupasupport@coupa.com", "employee_number"=>nil, "firstname"=>"Coupa", "lastname"=>"Support", "salesforce_id"=>nil, "custom_field_12"=>nil, "custom_field_11"=>nil, "date"=>nil, "dropdown"=>nil, "radio"=>nil, "custom_field_8"=>nil, "bussiness_unit"=>nil, "purchase"=>nil, "custom_field_3"=>nil, "number_oksana"=>nil, "gpo_entity"=>nil}, "updated_by"=>{"id"=>1528, "login"=>"test", "email"=>"test@test.com", "employee_number"=>nil, "firstname"=>"test", "lastname"=>"key", "salesforce_id"=>nil, "custom_field_12"=>nil, "custom_field_11"=>nil, "date"=>nil, "dropdown"=>nil, "radio"=>nil, "custom_field_8"=>nil, "bussiness_unit"=>nil, "purchase"=>nil, "custom_field_3"=>nil, "number_oksana"=>nil, "gpo_entity"=>nil}}, "created_by"=>{"id"=>1, "login"=>"coupasupport", "email"=>"upgrade+coupasupport@coupa.com", "employee_number"=>nil, "firstname"=>"Coupa", "lastname"=>"Support", "salesforce_id"=>nil, "custom_field_12"=>nil, "custom_field_11"=>nil, "date"=>nil, "dropdown"=>nil, "radio"=>nil, "custom_field_8"=>nil, "bussiness_unit"=>nil, "purchase"=>nil, "custom_field_3"=>nil, "number_oksana"=>nil, "gpo_entity"=>nil}, "updated_by"=>{"id"=>494, "login"=>"bhaskar", "email"=>"bhaskar@example.com", "employee_number"=>nil, "firstname"=>"Bhaskar", "lastname"=>"K", "salesforce_id"=>nil, "custom_field_12"=>nil, "custom_field_11"=>nil, "date"=>nil, "dropdown"=>nil, "radio"=>nil, "custom_field_8"=>nil, "bussiness_unit"=>nil, "purchase"=>nil, "custom_field_3"=>nil, "number_oksana"=>nil, "gpo_entity"=>nil}}, "account_allocations"=>[], "item"=>{"id"=>230, "created_at"=>"2012-12-12T21:40:06.000Z", "updated_at"=>"2015-06-24T05:44:30.000Z", "description"=>"The minimum requirement for this bid is:A blade enclosure cost (to include all components for it to work).A server blade to the minimum specification: 2 x 72GB Hard Disk; 2 x 100mbps Ethernet ports.The server blade (preferable) or the blade enclosure must have a slot for either a 1GB Ethernet card with 2 ports or a fibre Channel (HBA) with 2 ports.The cost of the blade enclosure and server blade must include 1 years maintenance to the level indicated in the RFP.The optional cost for years 2 and 3 maintenance is to the level indicated in the RFP.The installation services cost must include, un-boxing of the product, complete installation to agreed standards, removal of boxes from site.", "item_number"=>nil, "name"=>"RISC Server with 4 CPU and 16Gb RAM", "active"=>false, "storage_quantity"=>nil, "consumption_quantity"=>nil, "field"=>nil, "commodity"=>{"id"=>10, "created_at"=>"2011-04-12T16:28:24.000Z", "updated_at"=>"2011-04-12T21:58:19.000Z", "active"=>true, "name"=>"Hardware", "com_man"=>nil, "custom_field_4"=>nil, "custom_field_3"=>nil, "gl_code"=>nil, "acct"=>"Assets", "parent"=>{"id"=>2, "created_at"=>"2008-10-27T20:04:00.000Z", "updated_at"=>"2015-05-14T05:57:46.000Z", "active"=>true, "name"=>"IT", "com_man"=>nil, "custom_field_4"=>nil, "custom_field_3"=>nil, "gl_code"=>nil, "acct"=>"Indirect", "created_by"=>{"id"=>1, "login"=>"coupasupport", "email"=>"upgrade+coupasupport@coupa.com", "employee_number"=>nil, "firstname"=>"Coupa", "lastname"=>"Support", "salesforce_id"=>nil, "custom_field_12"=>nil, "custom_field_11"=>nil, "date"=>nil, "dropdown"=>nil, "radio"=>nil, "custom_field_8"=>nil, "bussiness_unit"=>nil, "purchase"=>nil, "custom_field_3"=>nil, "number_oksana"=>nil, "gpo_entity"=>nil}, "updated_by"=>{"id"=>494, "login"=>"bhaskar", "email"=>"bhaskar@example.com", "employee_number"=>nil, "firstname"=>"Bhaskar", "lastname"=>"K", "salesforce_id"=>nil, "custom_field_12"=>nil, "custom_field_11"=>nil, "date"=>nil, "dropdown"=>nil, "radio"=>nil, "custom_field_8"=>nil, "bussiness_unit"=>nil, "purchase"=>nil, "custom_field_3"=>nil, "number_oksana"=>nil, "gpo_entity"=>nil}}, "created_by"=>{"id"=>16, "login"=>"krhine", "email"=>"kevin.rhine@coupa.com", "employee_number"=>nil, "firstname"=>"Kevin", "lastname"=>"Rhine", "salesforce_id"=>nil, "custom_field_12"=>nil, "custom_field_11"=>nil, "date"=>nil, "dropdown"=>nil, "radio"=>nil, "custom_field_8"=>nil, "bussiness_unit"=>nil, "purchase"=>nil, "custom_field_3"=>nil, "number_oksana"=>nil, "gpo_entity"=>nil}, "updated_by"=>{"id"=>1, "login"=>"coupasupport", "email"=>"upgrade+coupasupport@coupa.com", "employee_number"=>nil, "firstname"=>"Coupa", "lastname"=>"Support", "salesforce_id"=>nil, "custom_field_12"=>nil, "custom_field_11"=>nil, "date"=>nil, "dropdown"=>nil, "radio"=>nil, "custom_field_8"=>nil, "bussiness_unit"=>nil, "purchase"=>nil, "custom_field_3"=>nil, "number_oksana"=>nil, "gpo_entity"=>nil}}, "uom"=>{"id"=>1, "created_at"=>nil, "updated_at"=>"2015-06-18T08:06:27.000Z", "code"=>"EA", "name"=>"Each", "allowable_precision"=>0, "active"=>true, "updated_by"=>{"id"=>1528, "login"=>"test", "email"=>"test@test.com", "employee_number"=>nil, "firstname"=>"test", "lastname"=>"key", "salesforce_id"=>nil, "custom_field_12"=>nil, "custom_field_11"=>nil, "date"=>nil, "dropdown"=>nil, "radio"=>nil, "custom_field_8"=>nil, "bussiness_unit"=>nil, "purchase"=>nil, "custom_field_3"=>nil, "number_oksana"=>nil, "gpo_entity"=>nil}}, "reorder_alerts"=>[], "created_by"=>{"id"=>1, "login"=>"coupasupport", "email"=>"upgrade+coupasupport@coupa.com", "employee_number"=>nil, "firstname"=>"Coupa", "lastname"=>"Support", "salesforce_id"=>nil, "custom_field_12"=>nil, "custom_field_11"=>nil, "date"=>nil, "dropdown"=>nil, "radio"=>nil, "custom_field_8"=>nil, "bussiness_unit"=>nil, "purchase"=>nil, "custom_field_3"=>nil, "number_oksana"=>nil, "gpo_entity"=>nil}, "updated_by"=>{"id"=>494, "login"=>"bhaskar", "email"=>"bhaskar@example.com", "employee_number"=>nil, "firstname"=>"Bhaskar", "lastname"=>"K", "salesforce_id"=>nil, "custom_field_12"=>nil, "custom_field_11"=>nil, "date"=>nil, "dropdown"=>nil, "radio"=>nil, "custom_field_8"=>nil, "bussiness_unit"=>nil, "purchase"=>nil, "custom_field_3"=>nil, "number_oksana"=>nil, "gpo_entity"=>nil}}, "currency"=>{"id"=>1, "code"=>"USD", "updated_by"=>{"id"=>1528, "login"=>"test", "email"=>"test@test.com", "employee_number"=>nil, "firstname"=>"test", "lastname"=>"key", "salesforce_id"=>nil, "custom_field_12"=>nil, "custom_field_11"=>nil, "date"=>nil, "dropdown"=>nil, "radio"=>nil, "custom_field_8"=>nil, "bussiness_unit"=>nil, "purchase"=>nil, "custom_field_3"=>nil, "number_oksana"=>nil, "gpo_entity"=>nil}}, "payment_term"=>{"id"=>1, "created_at"=>nil, "updated_at"=>"2015-06-16T07:23:04.000Z", "code"=>"Net 30", "description"=>nil, "days_for_net_payment"=>2, "days_for_discount_payment"=>nil, "discount_rate"=>nil, "active"=>true, "content_groups"=>[{"id"=>1, "created_at"=>"2006-08-28T02:40:04.000Z", "updated_at"=>"2015-06-17T09:43:58.000Z", "name"=>"Everyone", "description"=>"All users can see documents assigned to this group", "updated_by"=>{"id"=>494, "login"=>"bhaskar", "email"=>"bhaskar@example.com", "employee_number"=>nil, "firstname"=>"Bhaskar", "lastname"=>"K", "salesforce_id"=>nil, "custom_field_12"=>nil, "custom_field_11"=>nil, "date"=>nil, "dropdown"=>nil, "radio"=>nil, "custom_field_8"=>nil, "bussiness_unit"=>nil, "purchase"=>nil, "custom_field_3"=>nil, "number_oksana"=>nil, "gpo_entity"=>nil}}], "updated_by"=>{"id"=>1528, "login"=>"test", "email"=>"test@test.com", "employee_number"=>nil, "firstname"=>"test", "lastname"=>"key", "salesforce_id"=>nil, "custom_field_12"=>nil, "custom_field_11"=>nil, "date"=>nil, "dropdown"=>nil, "radio"=>nil, "custom_field_8"=>nil, "bussiness_unit"=>nil, "purchase"=>nil, "custom_field_3"=>nil, "number_oksana"=>nil, "gpo_entity"=>nil}}, "shipping_term"=>{"id"=>1, "created_at"=>nil, "updated_at"=>"2015-05-15T06:27:25.000Z", "code"=>"Standard", "description"=>nil, "active"=>true, "content_groups"=>[{"id"=>1, "created_at"=>"2006-08-28T02:40:04.000Z", "updated_at"=>"2015-06-17T09:43:58.000Z", "name"=>"Everyone", "description"=>"All users can see documents assigned to this group", "updated_by"=>{"id"=>494, "login"=>"bhaskar", "email"=>"bhaskar@example.com", "employee_number"=>nil, "firstname"=>"Bhaskar", "lastname"=>"K", "salesforce_id"=>nil, "custom_field_12"=>nil, "custom_field_11"=>nil, "date"=>nil, "dropdown"=>nil, "radio"=>nil, "custom_field_8"=>nil, "bussiness_unit"=>nil, "purchase"=>nil, "custom_field_3"=>nil, "number_oksana"=>nil, "gpo_entity"=>nil}}], "updated_by"=>{"id"=>494, "login"=>"bhaskar", "email"=>"bhaskar@example.com", "employee_number"=>nil, "firstname"=>"Bhaskar", "lastname"=>"K", "salesforce_id"=>nil, "custom_field_12"=>nil, "custom_field_11"=>nil, "date"=>nil, "dropdown"=>nil, "radio"=>nil, "custom_field_8"=>nil, "bussiness_unit"=>nil, "purchase"=>nil, "custom_field_3"=>nil, "number_oksana"=>nil, "gpo_entity"=>nil}}, "asset_tags"=>[], "attachments"=>[], "created_by"=>{"id"=>494, "login"=>"bhaskar", "email"=>"bhaskar@example.com", "employee_number"=>nil, "firstname"=>"Bhaskar", "lastname"=>"K", "salesforce_id"=>nil, "custom_field_12"=>nil, "custom_field_11"=>nil, "date"=>nil, "dropdown"=>nil, "radio"=>nil, "custom_field_8"=>nil, "bussiness_unit"=>nil, "purchase"=>nil, "custom_field_3"=>nil, "number_oksana"=>nil, "gpo_entity"=>nil}, "updated_by"=>{"id"=>494, "login"=>"bhaskar", "email"=>"bhaskar@example.com", "employee_number"=>nil, "firstname"=>"Bhaskar", "lastname"=>"K", "salesforce_id"=>nil, "custom_field_12"=>nil, "custom_field_11"=>nil, "date"=>nil, "dropdown"=>nil, "radio"=>nil, "custom_field_8"=>nil, "bussiness_unit"=>nil, "purchase"=>nil, "custom_field_3"=>nil, "number_oksana"=>nil, "gpo_entity"=>nil}}
+requisition_header.id5545
+requisition_header.created_at2015-06-24T05:48:19.000Z
+requisition_header.updated_at2015-06-24T05:48:19.000Z
+requisition_header.buyer_note
+requisition_header.need_by_date
+requisition_header.reject_reason_comment
+requisition_header.statusdraft
+requisition_header.submitted_at
+requisition_header.exportedfalse
+requisition_header.ship_to_attentionCoupa Support
+requisition_header.total2049.0
+requisition_header.mobile_total2049.0
+requisition_header.custom_field_4
+requisition_header.custom_field_3
+requisition_header.zcust
+requisition_header.custom_field_1
+requisition_header.currency{"id"=>1, "code"=>"USD", "updated_by"=>{"id"=>1528, "login"=>"test", "email"=>"test@test.com", "employee_number"=>nil, "firstname"=>"test", "lastname"=>"key", "salesforce_id"=>nil, "custom_field_12"=>nil, "custom_field_11"=>nil, "date"=>nil, "dropdown"=>nil, "radio"=>nil, "custom_field_8"=>nil, "bussiness_unit"=>nil, "purchase"=>nil, "custom_field_3"=>nil, "number_oksana"=>nil, "gpo_entity"=>nil}}
+requisition_header.approvals[]
+requisition_header.created_by{"id"=>494, "login"=>"bhaskar", "email"=>"bhaskar@example.com", "employee_number"=>nil, "firstname"=>"Bhaskar", "lastname"=>"K", "salesforce_id"=>nil, "custom_field_12"=>nil, "custom_field_11"=>nil, "date"=>nil, "dropdown"=>nil, "radio"=>nil, "custom_field_8"=>nil, "bussiness_unit"=>nil, "purchase"=>nil, "custom_field_3"=>nil, "number_oksana"=>nil, "gpo_entity"=>nil}
+requisition_header.updated_by{"id"=>494, "login"=>"bhaskar", "email"=>"bhaskar@example.com", "employee_number"=>nil, "firstname"=>"Bhaskar", "lastname"=>"K", "salesforce_id"=>nil, "custom_field_12"=>nil, "custom_field_11"=>nil, "date"=>nil, "dropdown"=>nil, "radio"=>nil, "custom_field_8"=>nil, "bussiness_unit"=>nil, "purchase"=>nil, "custom_field_3"=>nil, "number_oksana"=>nil, "gpo_entity"=>nil}
+requisition_header.mobile_currency{"id"=>1, "code"=>"USD", "updated_by"=>{"id"=>1528, "login"=>"test", "email"=>"test@test.com", "employee_number"=>nil, "firstname"=>"test", "lastname"=>"key", "salesforce_id"=>nil, "custom_field_12"=>nil, "custom_field_11"=>nil, "date"=>nil, "dropdown"=>nil, "radio"=>nil, "custom_field_8"=>nil, "bussiness_unit"=>nil, "purchase"=>nil, "custom_field_3"=>nil, "number_oksana"=>nil, "gpo_entity"=>nil}}

Note:
-requisition_header.requisition_lines[0]
present in both input and output JSON but not compared..
Please revert me with solution asap.

Thanks,
Bhaskar

requisition_header.requisition_lines[0] is very different in JSON_1 and JSON_2, so it reports - and +.

From the result you can see requisition_header.requisition_lines[0] is there both in JSON_1 and JSON_2

but as per the out put i.e after diff it is mentioned that requisition_header.requisition_lines[0] does not exist in JSON_2 instead comparing its content inside it.

Please use your hashdiff app that you hosted on heroku.

I see requisition_header.requisition_lines[0] is there both in JSON_1 and JSON_2, but they are very different, so the algorithm treats them as two different object, thus not compare them recursively.

  • requisition_header.requisition_lines[0]{"item"=>{"name"=>"RISC Server with 4 CPU and 16Gb RAM"}, "line_num"=>1, "need_by_date"=>"2010-09-23T07:00:00.000Z", "account"=>{"code"=>"SF-Marketing-Indirect", "account_type"=>{"name"=>"Ace Corporate"}}}

The '-' means the element or key does not exist in json_2. but it is there. What I mean is the key itself is not found then how it can compare the data of key can be compared?

@liufengyun Can you share your skype id?

The '-' means the element or key does not exist in json_2

@kotubhaskar that's a misunderstanding. For arrays, - means the element is completely changed.

Sorry that I'm not on Skype most of the time. I'd like to keep the discussion here, so that it might be helpful to others as well.