Class JSON

java.lang.Object
com.yahoo.text.JSON

public final class JSON extends Object
Static methods for working with JSON.
Author:
bratseth
  • Method Details

    • encode

      public static String encode(Map<String,?> map)
      Outputs a map as a JSON 'object' string, provided that the map values are either
      • String
      • Number
      • Any object whose toString returns JSON
    • escape

      public static String escape(String s)
      Returns the given string as a properly json escaped string
    • equals

      public static boolean equals(String left, String right)
      Test whether two JSON strings are equal, e.g. the order of fields in an object is irrelevant.

      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
    • canonical

      public static String canonical(String jsonString)