GREL multivalued JSON

72 views Asked by At

I have a column with following contents in Open Refine

1. {"result":"Mango"}
2. {"result":"Banana"},{"result":"Apple"}

and I need resulting column

1. Mango
2. Banana | Apple

The expression I tried was

"forEach(value.parseJson().result).join(' | ')"

but this does not produce results.

2

There are 2 answers

0
Tom Morris On

Your second example isn't valid JSON, so I'm not sure what the parse will produce -- probably just the first object. One approach would be to wrap each cell with square brackets ([]) to turn it into a JSON array. This will give you something that forEach can operate on.

0
Vijay Barve On

Thanks @Tom Morris

Modified cells as

1. [{"result":"Mango"}]
2. [{"result":"Banana"},{"result":"Apple"}]

Then solution used was

forEach(value.parseJson(),v,v.result).join(' | ')