CodeIgniter Forums

Full Version: creating a json structure
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am using fusionAuth. The way it works is that I need to create a json structure called a request, Here is an example of one. Any idea how to create one in CI? 

Code:
{
  "applicationId": "10000000-0000-0002-0000-000000000001",
  "loginId": "[email protected]",
  "state": {
    "client_id": "10000000-0000-0002-0000-000000000001",
    "redirect_uri": "https://piedpiper.com/callback",
    "response_type": "code",
    "scope": "openid",
    "state": "CSRF123"
  }
}
Create it using an associated array then json_encode it.
I think:
$root = [
'data' = [

],
'status' = '',
'...' = '...'
];

return json_encode($root);
(09-24-2020, 01:05 PM)richb201 Wrote: [ -> ]I am using fusionAuth. The way it works is that I need to create a json structure called a request, Here is an example of one. Any idea how to create one in CI? 

Code:
{
  "applicationId": "10000000-0000-0002-0000-000000000001",
  "loginId": "[email protected]",
  "state": {
    "client_id": "10000000-0000-0002-0000-000000000001",
    "redirect_uri": "https://piedpiper.com/callback",
    "response_type": "code",
    "scope": "openid",
    "state": "CSRF123"
  }
}
Depending on your source of information this is how i do it: 
Code:
$response = [
'applicationId' => '10000000-0000-0002-0000-000000000001',
'loginId'   => [email protected],
'state' => []
];

foreach($propertyimages as $row){
$response['state'][] = [
'client_id' => $row->client_id,
'redirect_uri' => $row->redirect_uri,
'response_type' => $row->response_type,
'scope' => $row->scope,
];

If you not looping through data i guess you will know what to do.