Vijay Barve
Vijay Barve

Reputation: 325

GREL multivalued JSON

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.

Upvotes: 1

Views: 74

Answers (2)

Vijay Barve
Vijay Barve

Reputation: 325

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(' | ')

Upvotes: 1

Tom Morris
Tom Morris

Reputation: 10540

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.

Upvotes: 1

Related Questions