Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for delete json keys in inja template #348

Open
nmnellis opened this issue Jun 14, 2024 · 0 comments
Open

Support for delete json keys in inja template #348

nmnellis opened this issue Jun 14, 2024 · 0 comments

Comments

@nmnellis
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants