Groovy web console

subscribe to the feed Subscribe
to this
site

Test Tailorsoft

Published 1 month ago by Andres Escobar with tags order sample
Actions Execute script  ▶ Edit in console Back to console Show/hide line numbers View recent scripts
import groovy.json.JsonSlurper

def url_Json = new URL("https://www.tailorsoft.co/sample.json")
def json = new JsonSlurper().parseText( url_Json.text )
def products = json.products
def orders = json.orders

orders.each { x ->  
println "+--------------------+";
    println "order: ${x.id}"
    println "Products"
    Double total = 0
    x.items.each{i -> 
       products.findAll{v -> v.id == i.productId}.each{items -> 
        println   "id: ${items.id} name: ${items.name} price: ${items.price}"
        total += Double.parseDouble(items.price) 
       }
    }
    println "  ----Total----  ";
    println " = "+total
    println "  ----Fin----  ";
}