0

I would like to add some data and change the structure of an API response. Is their any service which supports this feature? So for example:

I have the following API response:

[
  {"text-message": "Welcome to our store!"},
  {"text-message": "How can I help you?"}
]

and I want to change it to:

[
  {"text": "Welcome to our store!"},
  {"text": "How can I help you?"}
]
Robert Keus
  • 79
  • 1
  • 7
  • 2
    This has little to do with `facebook` or `facebook-messenger` – please tag such general questions more appropriately. (`json` might be an obvious one, plus the programming languages you want to use.) – CBroe Jul 20 '16 at 11:09
  • From the structure of the JSON it looks like the poster is working on a Facebook chatbot. – Metablocks Corp Aug 01 '16 at 06:32

1 Answers1

0

Those things are pretty easy with Array map: http://php.net/manual/function.array-map.php

...or the JavaScript version: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array/map

For example (with JS):

yourArray.map((obj) => { 
    return {
        'text': obj['text-message']
    };
});
andyrandy
  • 72,880
  • 8
  • 113
  • 130