Ask Your Question
1

How to convert a Map typed field to a Json string typed field?

asked 2018-07-11 22:20:57 -0500

casel.chen gravatar image

I tried with "Field Converter", it said "Can't convert Map to String". Then I tried with JavaScript by using "JSON.stringify(map)", but the result is "undefined". So my question is "How to convert a Map typed field to a Json string typed field in SDC?".

edit retag flag offensive close merge delete

Comments

Hi Casel! Can you provide sample input and desired output?

iamontheinet gravatar imageiamontheinet ( 2018-07-12 10:38:43 -0500 )edit

My data has a "foo" field, like this "foo": {"id": 123, "name": "bar"}, I want to get "foot": "{\"id\": 123, "name": \"bar\"}", a json string reprsent of map.

casel.chen gravatar imagecasel.chen ( 2018-07-12 11:12:56 -0500 )edit

How is your 'map' being fed into the JavaScript evaluator? I created a pipeline with "foo": {"id": 123, "name": "bar"} as my data; added JavaScript code records[i].value.rec = JSON.stringify(records[i].value.text); and I got the desired output "\"foo\": {\"id\": 123, \"name\": \"bar\"}"

iamontheinet gravatar imageiamontheinet ( 2018-07-12 11:40:48 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2018-07-18 20:21:01 -0500

metadaddy gravatar image

You can use the JSON Generator processor to do this. Just specify the field you want to encode, for example, /foo and the field where you want the output to go - this can be the same field if you want. For example:

image description

edit flag offensive delete link more

Comments

Cool & Thanks!

casel.chen gravatar imagecasel.chen ( 2018-07-18 20:36:26 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2018-07-11 22:20:57 -0500

Seen: 33 times

Last updated: Jul 18