Flexibel JSON

Flexibel JSON

nessinitsnessinits Posts: 86Questions: 27Answers: 0

Got a question,perhaps a request:

Currently the JSON structure is fixed: {"data":[],"options":[],"files":[]}
Is it possible to add parts to the current JSON structure, like this: {"data":[],"options":[],"files":[],"messages":["Notification"]}

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,455Questions: 1Answers: 10,465 Site admin
    Answer ✓

    Absolutely! Are you using the PHP libraries? You can use the Editor->data() method to get the data structure and then modify it as you wish before sending it to the client-side:

    $json = new Editor( ... )
      ->fields( ... )
      ->process( $_POST )
      ->data();
    
    $json['messages'] = [];
    $json['messages'][] = 'Notification';
    
    echo json_encode( $json );
    

    The .NET and NodeJS libraries have a similar data method on the Editor class.

    Allan

This discussion has been closed.