Writing to a json file in workspace using Jenkins

Config File Provider Plugin doesn't allow you to pass parameters to configuration files. You can solve your problem with any scripting language. My favorite approach is using Groovy plugin. Hit a check-box "Execute system Groovy script" and paste the following script:

import groovy.json.*

// read build parameters
env = build.getEnvironment(listener)
environment = env.get('environment')
filename = env.get('filename')

// prepare json
def builder = new JsonBuilder()
builder environment: environment, filename: filename
json = builder.toPrettyString()

// print to console and write to a file
println json
new File(build.workspace.toString() + "\\job.json").write(json)

Output sample:

{
    "environment": "ENV2",
    "filename": "abc.txt"
}

With Pipeline Utility Steps plugin this is very easy to achieve.

    jsonfile = readJSON file: 'path/to/your.json'
    jsonfile['environment'] = 'ENV2'
    writeJSON file: 'path/to/your.json', json: jsonfile