# Splitting an object into two separate objects

**URL:** <https://discourse.nodered.org/t/splitting-an-object-into-two-separate-objects/94897>\
**Category:** General\
**Tags:** split\
**Created:** [25 January 2025 07:06 UTC](https://discourse.nodered.org/t/splitting-an-object-into-two-separate-objects/94897 "2025-01-25T07:06:21Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![iainmac](https://avatars.discourse-cdn.com/v4/letter/i/a9a28c/32.png) [@iainmac](https://discourse.nodered.org/u/iainmac)\
**Post date:** [25 January 2025 07:06 UTC](https://discourse.nodered.org/t/splitting-an-object-into-two-separate-objects/94897/1 "2025-01-25T07:06:21Z")

</div>

Hi There,

I have an object in my message payload (payload.Time) that I would like to split into two separate objects. I think the answer must be really simple with a function node I guess but I am just hitting a stumbling block.  
The string appears to be a fixed length.

Hopefully the picture explains my aim.  
Change the single string in payload.Time to 2 strings 1) payload.Date & 2)payload.Time

 ![](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/c/6c98c2736edd1421f9f0bd75b60b07462c78a049.jpeg)

Thanks Iain

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [25 January 2025 07:30 UTC](https://discourse.nodered.org/t/splitting-an-object-into-two-separate-objects/94897/2 "2025-01-25T07:30:28Z")

</div>

There are multiple ways, example in function node

```auto
const input = msg.payload.Time.split("T")
const date = input[0]
const time = input[1]
msg.payload = {date,time}

return msg

```

or use

```auto
msg.payload = {date_time:{date,time}}

```

if you want to have them sitting inside another property.  
Small tip, don't use 'exotic' characters in property names, it will come to bite you later.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [25 January 2025 07:58 UTC](https://discourse.nodered.org/t/splitting-an-object-into-two-separate-objects/94897/3 "2025-01-25T07:58:56Z")

</div>

I think the op wants to keep the other data.

```auto
const input = msg.payload.Time.split("T")
const date = input[0]
const time = input[1]
msg.payload.dateTime = {date, time}
return msg

```

---

<div class="post-metadata">

**Author:** ![iainmac](https://avatars.discourse-cdn.com/v4/letter/i/a9a28c/32.png) [@iainmac](https://discourse.nodered.org/u/iainmac)\
**Post date:** [25 January 2025 08:01 UTC](https://discourse.nodered.org/t/splitting-an-object-into-two-separate-objects/94897/4 "2025-01-25T08:01:28Z")

</div>

Much appreciated bakman2. Second use case was exactly what I was after

> [@bakman2](#):
>
> `msg.payload = {date_time:{date,time}}`

---

<div class="post-metadata">

**Author:** ![iainmac](https://avatars.discourse-cdn.com/v4/letter/i/a9a28c/32.png) [@iainmac](https://discourse.nodered.org/u/iainmac)\
**Post date:** [25 January 2025 08:03 UTC](https://discourse.nodered.org/t/splitting-an-object-into-two-separate-objects/94897/5 "2025-01-25T08:03:43Z")

</div>

Yes I did, I'm somewhat hesitant to ask for everything to be done for me though 😉

---

<div class="post-metadata">

**Author:** ![iainmac](https://avatars.discourse-cdn.com/v4/letter/i/a9a28c/32.png) [@iainmac](https://discourse.nodered.org/u/iainmac)\
**Post date:** [25 January 2025 09:41 UTC](https://discourse.nodered.org/t/splitting-an-object-into-two-separate-objects/94897/6 "2025-01-25T09:41:11Z")

</div>

Thank You both @bakman2 & @Steve-Mcl

 ![Solved](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/f/9fb917ce9ffb7f1aa26f95c62f867c91aa3f0a0d.jpeg)

[Time Extraction Tests.json](https://discourse.nodered.org/uploads/short-url/w6QMhDMVFb0x5xpWRzegTdXaxj7.json) (3.7 KB)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [8 February 2025 09:42 UTC](https://discourse.nodered.org/t/splitting-an-object-into-two-separate-objects/94897/7 "2025-02-08T09:42:07Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
