// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.text; import com.yahoo.slime.Slime; import com.yahoo.slime.SlimeUtils; import java.util.Map; /** * Static methods for working with JSON. * * @author bratseth */ public final class JSON { /** No instances */ private JSON() {} /** * Outputs a map as a JSON 'object' string, provided that the map values * are either *
When comparing two numbers of the two JSON strings, the result is only guaranteed to be * correct if (a) both are integers (without fraction and exponent) and each fits in a long, or * (b) both are non-integers, fits in a double, and are syntactically identical. Examples * of pairs that may not be equal: 1 and 1.0 (different types), 0.1 and 1e-1, 0.0 and 0.00.
* * @throws RuntimeException on invalid JSON */ public static boolean equals(String left, String right) { Slime leftSlime = SlimeUtils.jsonToSlimeOrThrow(left); Slime rightSlime = SlimeUtils.jsonToSlimeOrThrow(right); return leftSlime.equalTo(rightSlime); } public static String canonical(String jsonString) { return SlimeUtils.jsonToSlimeOrThrow(jsonString).toString(); } }