Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Merging 2 different JSON objects

Merging 2 different JSON objects

Scheduled Pinned Locked Moved C#
jsontutorialquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    Farhad Eft
    wrote on last edited by
    #1

    Hi, I have two JSON objects: JSON Object 1

    [{
    "date":
    [
    "date-value1",
    "date-value2,
    ........ ,
    "date-value729"
    ]
    }]

    JSON Object 2

    {
    "data": [
    {
    "body": [ "body1" ],
    "link": "link1",
    "title": [ "title1" ]
    },
    ...........
    {
    "body": [ "body729" ],
    "link": "link729",
    "title": [ "title729" ]
    }
    ]
    }

    How can I merge the properties of these 2 JSON objects and have the following example as an output for all 729 records of data:

    {
    "data": [
    {
    "body": [ "body1" ],
    "link": "link1",
    "title": [ "title1" ].
    "date": "date1"
    },
    ...........
    {
    "body": [ "body729" ],
    "link": "link729",
    "title": [ "title729" ]
    "date": "date729"
    }
    ]
    }

    Examples that I found online are mainly about merging two identical JSON objects. Thank you in advance for your time and consideration.

    L 1 Reply Last reply
    0
    • F Farhad Eft

      Hi, I have two JSON objects: JSON Object 1

      [{
      "date":
      [
      "date-value1",
      "date-value2,
      ........ ,
      "date-value729"
      ]
      }]

      JSON Object 2

      {
      "data": [
      {
      "body": [ "body1" ],
      "link": "link1",
      "title": [ "title1" ]
      },
      ...........
      {
      "body": [ "body729" ],
      "link": "link729",
      "title": [ "title729" ]
      }
      ]
      }

      How can I merge the properties of these 2 JSON objects and have the following example as an output for all 729 records of data:

      {
      "data": [
      {
      "body": [ "body1" ],
      "link": "link1",
      "title": [ "title1" ].
      "date": "date1"
      },
      ...........
      {
      "body": [ "body729" ],
      "link": "link729",
      "title": [ "title729" ]
      "date": "date729"
      }
      ]
      }

      Examples that I found online are mainly about merging two identical JSON objects. Thank you in advance for your time and consideration.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      You would need to do it manually. Create a class for each type, and one that contains all the properties. Read the two sets into the first two classes, merge the properties into the third, and create a new JSON stream from that.

      F 1 Reply Last reply
      0
      • L Lost User

        You would need to do it manually. Create a class for each type, and one that contains all the properties. Read the two sets into the first two classes, merge the properties into the third, and create a new JSON stream from that.

        F Offline
        F Offline
        Farhad Eft
        wrote on last edited by
        #3

        Thanks, it worked as you guided. I thought maybe there is already some sort of online tools to import and export such task.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups