markej
asked on
Adding Metadata to JSON Payloads
I need to provide a JSON feed that looks like this:
{"redirect_flows": {
"description": "Wine boxes",
"session_token": "SESS_wSs0uGYMISxzqOBq",
"success_redirect_url": "https://example.com/pay/confirm", "prefilled_customers": { "email":"emailaddress","gi ven_name": "firstname ","family_ name":"las tname","ad dress_line 1":"addres s1 Road","address_line2":null ,"city":"L ondon","po stal_code" :"postcode ","country _code":"GB " }, "links": { "creditor": "CR123" }}}
I've been using the JavaScriptSerializer to serialize the data in a similar BUT simpler JSON feed and using replace to tweak the feed to go from this:
[{"email":"emailaddress"," given_name ":"firstna me","famil y_name":"l astname"," address_li ne1":"addr ess1 Road","address_line2":null ,"city":"L ondon","po stal_code" :"postcode ","country _code":"GB ")]
to this:
{ "customers" : { "email":"emailaddress","gi ven_name": "firstname ","family_ name":"las tname","ad dress_line 1":"addres s1 Road","address_line2":null ,"city":"L ondon","po stal_code" :"postcode ","country _code":"GB ", "metadata": {"customerid":"124"}}}
Can someone help me and show me how I can add the metadata programmatically and more importantly scalable so I don't have to use the replace etc. every time?
Thanks
Mark
{"redirect_flows": {
"description": "Wine boxes",
"session_token": "SESS_wSs0uGYMISxzqOBq",
"success_redirect_url": "https://example.com/pay/confirm", "prefilled_customers": { "email":"emailaddress","gi
I've been using the JavaScriptSerializer to serialize the data in a similar BUT simpler JSON feed and using replace to tweak the feed to go from this:
[{"email":"emailaddress","
to this:
{ "customers" : { "email":"emailaddress","gi
Can someone help me and show me how I can add the metadata programmatically and more importantly scalable so I don't have to use the replace etc. every time?
Thanks
Mark
Can you not use NewtonSoft Json.NET library?
ASKER
What's that and where do I get it and documentation? and more important how would I do this using it?
Better visit the official web site. Loads of documentation there.
I haven't used it in Visual Basic.NET. However you create the class that matches the required json representation. Populate the class with the data (object) and serialise it to json.
The other way round (deserialise) is also possible.
I haven't used it in Visual Basic.NET. However you create the class that matches the required json representation. Populate the class with the data (object) and serialise it to json.
The other way round (deserialise) is also possible.
This question needs an answer!
Become an EE member today
7 DAY FREE TRIALMembers can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.