WordPress.org

Forums

JSON API
Modify JSON response (3 posts)

  1. Shijo64
    Member
    Posted 1 year ago #

    Hi, I want to know if there is any way to modify the JSON that I get when using get_post function?, I need to modify it, thanks in advance

    https://wordpress.org/plugins/json-api/

  2. Cadu de Castro Alves
    Member
    Posted 1 year ago #

    You can use json_api_encode filter, like the following example:

    function turismogdf_remove_html_tags( $response ) {
    $post = '';
    if( isset( $response['posts'] ) ) {
    foreach( $response['posts'] as $post ) {
    $post->content = strip_tags( $post->content );
    $post->excerpt = strip_tags( $post->excerpt );
    }
    } else if( $response['post'] ) {
    $post = $response['post'];
    $post->content = strip_tags( $post->content );
    $post->excerpt = strip_tags( $post->excerpt );
    }
    return $response;
    }
    add_filter( 'json_api_encode', 'turismogdf_remove_html_tags' );

  3. Marcos Curvello
    Member
    Posted 1 year ago #

    @Cadu de Castro Alves

    Hey where do I place the following code?

    I'm creating a iOS app, and I am using this JSON plugin to convert wp data so the app can consume it. But when the app parses the JSON there many unwanted html tags and html special characters.

    I'm having a hard time customizing this plugin, for example this section:

    3.1. Output-modifying arguments.

    I want change these settings and see which will work best for me , but I don't know where to insert these lines:

    json_unescaped_unicode
    json_encode

    Help me out please, can you point me to in the right direction here ?

    Thanks in Advance

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • JSON API
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic

Tags