Skip to content

Support for delete json keys in inja template #348

Open
@nmnellis

Description

Univision is looking to remove some json keys from the body if certain properties.

Here is the javascript code they currently use to remove it

var content = context.getVariable("request.content")
if ( content !== '' ) { 
    if ( JSON.parse(content).hasOwnProperty('video') ) {
        var payload = JSON.parse(content)
        video = payload['video']; 
        if ( video.hasOwnProperty('mediaId') ) {
            var mediaid = payload['video']['mediaId']+"";
            if ( mediaid.match(/^transmission:matchid:.*/) ) {
                payload['video']['mediaId'] = "video:mcp:unexpected-live-match";
                context.setVariable('request.content', JSON.stringify(payload));
            }
        }
        if ( video.hasOwnProperty('seriesMediaId') ) {
            var seriesmediaid = payload['video']['seriesMediaId'];
            if ( seriesmediaid === "" ) { 
                delete payload['video']['seriesMediaId'];
                if ( video.hasOwnProperty('nextEpisodeMediaId') ) {
                    delete payload['video']['nextEpisodeMediaId'];
                }   
                context.setVariable('request.content', JSON.stringify(payload))
            }
        } else if ( video.hasOwnProperty('nextEpisodeMediaId') ) {
            delete payload['video']['nextEpisodeMediaId'];
            context.setVariable('request.content', JSON.stringify(payload))
        } 
    } else {
        context.setVariable('vixdebug.remove_empty_series_media_id','payload does not have a json video object')
    }
}

PR: #347

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions