JSON - How to search and replace values

How can I search and replace values in JSON?
I want to replace the values in the 'docs' with the values in the 'highlighting'.  So I can bind the highlighted with the <em> tag.

Any ideas?

            var data = [
                               "name":"Apple 60 GB iPod with Video Playback Black",
                               "manu":"Apple Computer Inc.",
                               "includes":"earbud headphones, USB cable",
                                "iTunes, Podcasts, Audiobooks",
                                "Stores up to 15,000 songs, 25,000 photos, or 150 hours of video",
                                "2.5-inch, 320x240 color TFT LCD display with LED backlight",
                                "Up to 20 hours of battery life",
                                "Plays AAC, MP3, WAV, AIFF, Audible, Apple Lossless, H.264 video",
                                "Notes, Calendar, Phone book, Hold button, Date display, Photo wallet, Built-in games, JPEG photo playback, Upgradeable firmware, USB 2.0 compatibility, Playback speed control, Rechargeable capability, Battery level indication"]},
                               "name":"ASUS Extreme N7800GTX/2DHTV (256 MB)",
                               "manu":"ASUS Computer Inc.",
                                "graphics card"],
                                "NVIDIA GeForce 7800 GTX GPU/VPU clocked at 486MHz",
                                "256MB GDDR3 Memory clocked at 1.35GHz",
                                "PCI Express x16",
                                "Dual DVI connectors, HDTV out, video input",
                                "OpenGL 2.0, DirectX 9.0"]},
                               "name":"ATI Radeon X1900 XTX 512 MB PCIE Video Card",
                               "manu":"ATI Technologies",
                                "graphics card"],
                                "ATI RADEON X1900 GPU/VPU clocked at 650MHz",
                                "512MB GDDR3 SDRAM clocked at 1.55GHz",
                                "PCI Express x16",
                                "dual DVI, HDTV, svideo, composite out",
                                "OpenGL 2.0, DirectX 9.0"]}]
                            "name":["Apple 60 GB iPod with <em>Video</em> Playback Black"],
                            "features":["Stores up to 15,000 songs, 25,000 photos, or 150 hours of <em>video</em>"]},
                            "features":["Dual DVI connectors, HDTV out, <em>video</em> input"]},
                            "name":["ATI Radeon X1900 XTX 512 MB PCIE <em>Video</em> Card"]}}          
Who is Participating?
Robert SchuttConnect With a Mentor Software EngineerCommented:
Maybe something like this:
  $.each(data, function(idx1, obj1) {
    $.each(obj1.highlighting, function(idx2, obj2) {
      $.each(obj1.response.docs, function(idx3, obj3) {
        if (obj3.id == idx2) {
          $.each(obj2, function(idx4, obj4) {
            if (idx4 in obj3) {
              obj3[idx4] = obj2[idx4];

Open in new window

I also made a jsfiddle to show the results.
JElsterAuthor Commented:
Awesome!  again!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.