Groovy web console

subscribe to the feed Subscribe
to this

Replace inline

Published 2 months ago by MadaManu
Actions Execute script  ▶ Edit in console Back to console Show/hide line numbers View recent scripts
import groovy.json.JsonBuilder
import groovy.json.JsonSlurper

URL fileUrl = new URL("")
def fileContent = new JsonSlurper().parseText(fileUrl.text)

for(e in fileContent["pEntity"]){
    def entry = e.value
    replaceValue("available_points", "map:achieved_level", entry)

def replaceValue(def replaceWho, def replaceWith, def entry) {
        entry[replaceWho] = entry[replaceWith.replace("map:", "")]
    } else {
        entry[replaceWho] = replaceWith

println new JsonBuilder(fileContent).toPrettyString()