# Convert array into single value of property (resolving arrays)

**URL:** <https://community.neo4j.com/t/convert-array-into-single-value-of-property-resolving-arrays/60022>\
**Category:** Neo4j Graph Platform\
**Tags:** migrated\
**Created:** [July 10, 2022, 5:55pm UTC](https://community.neo4j.com/t/convert-array-into-single-value-of-property-resolving-arrays/60022 "2022-07-10T17:55:01Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jana\_cyrus](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/jana_cyrus/32/21860_2.png) [@jana\_cyrus](https://community.neo4j.com/u/jana_cyrus)\
**Post date:** [July 10, 2022, 5:55pm UTC](https://community.neo4j.com/t/convert-array-into-single-value-of-property-resolving-arrays/60022/1 "2022-07-10T17:55:01Z")

</div>

Hi,

I have a lot of nodes in my database that all have different properties. I don't know what properties a node exactly has because I automatically integrate the data. Because of my settings all properties of the nodes are stored as arrays. I'm looking for a way to convert the properties that only hold a single value into a string. Is there an easy way to do this?

I already have a solution for a propety that I know all nodes contain.

```auto
MATCH (n:BTOOntology) WHERE n.id IS NOT NULL UNWIND n.id as ID SET n.id=replace(ID,":","_");

```

However I don't want to do this for every property, so I'm looking for a more general solution where I can do this for all properties of one node especially since I don't know what properties a node has.

Thanks in advance!

Cheers, Jana

P.S. For those interested:

I integrate ontologies into a Neo4j graph database using neosemantics. Because I use the parameter

handleMultival: "ARRAY"

all property values of a node are stored as arrays.

---

<div class="post-metadata">

**Author:** ![glilienfield](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/glilienfield/32/27534_2.png) [@glilienfield](https://community.neo4j.com/u/glilienfield)\
**Post date:** [July 10, 2022, 6:42pm UTC](https://community.neo4j.com/t/convert-array-into-single-value-of-property-resolving-arrays/60022/2 "2022-07-10T18:42:45Z")

</div>

Can you describe how these properties are encoded into an array? What is the reason you don’t store them as individual properties?

---

<div class="post-metadata">

**Author:** ![Cobra](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/cobra/32/35243_2.png) [@Cobra](https://community.neo4j.com/u/Cobra)\
**Post date:** [July 11, 2022, 6:55am UTC](https://community.neo4j.com/t/convert-array-into-single-value-of-property-resolving-arrays/60022/3 "2022-07-11T06:55:03Z")

</div>

Hello [@jana\_cyrus](https://community.neo4j.com/t5/user/viewprofilepage/user-id/12882) 😊

It's not very clear what you try to achieve.

You want to convert the property to string if the array has only one value?

Regards,  
Cobra

---

<div class="post-metadata">

**Author:** ![jana\_cyrus](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/jana_cyrus/32/21860_2.png) [@jana\_cyrus](https://community.neo4j.com/u/jana_cyrus)\
**Post date:** [July 14, 2022, 1:38pm UTC](https://community.neo4j.com/t/convert-array-into-single-value-of-property-resolving-arrays/60022/4 "2022-07-14T13:38:50Z")

</div>

Hi, yes I want to convert the property to a string if the array has one value.

The properties are in an array because I import data that can have more than one value for one property key. If I wouldn't store them in an array they would be overwritte during the import.

For example every node has the property label which can be something like label=[cell], but other nodes can have more than one value for the property label, e.g. label=[cancer, cancer cell].

I already found a solution. I use this command to return all property keys.

```auto
MATCH(n:BTOOntology) WITH KEYS(n) AS keys 
UNWIND keys AS key 
RETURN DISTINCT COLLECT(DISTINCT key);

```

Because I write a Python script with Py2neo I can then iterate through the list of keys and convert the array into a string when the array has the size 1.

```auto
MATCH(n:BTOOntology) 
WHERE size(n.'+key+')=1 
UNWIND n.'+key+' as PROP 
SET n.'+key+' = PROP;

```

Cheers,

Jana

---

<div class="post-metadata">

**Author:** ![glilienfield](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/glilienfield/32/27534_2.png) [@glilienfield](https://community.neo4j.com/u/glilienfield)\
**Post date:** [July 14, 2022, 11:56pm UTC](https://community.neo4j.com/t/convert-array-into-single-value-of-property-resolving-arrays/60022/5 "2022-07-14T23:56:44Z")

</div>

You will not be able to use the approach in your second query, as the 'size' method is only valid for strings and lists. You will get an error if passing a property of any other type. You don't know the properties that are lists?
