Link to home
Start Free TrialLog in
Avatar of markej
markejFlag for United Kingdom of Great Britain and Northern Ireland

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","given_name":"firstname","family_name":"lastname","address_line1":"address1 Road","address_line2":null,"city":"London","postal_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":"firstname","family_name":"lastname","address_line1":"address1 Road","address_line2":null,"city":"London","postal_code":"postcode","country_code":"GB")]
to this:
{ "customers" : { "email":"emailaddress","given_name":"firstname","family_name":"lastname","address_line1":"address1 Road","address_line2":null,"city":"London","postal_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
Avatar of Nitin Sontakke
Nitin Sontakke
Flag of India image

Can you not use NewtonSoft Json.NET library?
Avatar of markej

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.
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members 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.