Class Json

java.lang.Object
ucar.unidata.util.Json

public class Json extends Object
  • Field Details

  • Constructor Details

    • Json

      public Json()
  • Method Details

    • addGeolocation

      public static void addGeolocation(Appendable pw, double lat, double lon, double elevation) throws Exception
      _more_
      Parameters:
      pw - _more_
      lat - _more_
      lon - _more_
      elevation - _more_
      Throws:
      Exception - _more_
    • mapAndQuote

      public static String mapAndQuote(String... values)
      Create a JSON map
      Parameters:
      values - key/value pairs { key1,value1,key2,value2 }
      Returns:
      the map object { key1:value1, key2:value2 }
    • map

      public static String map(String... values)
      Create a JSON map
      Parameters:
      values - key/value pairs { key1,value1,key2,value2 }
      Returns:
      the map object { key1:value1, key2:value2 }
    • map

      public static String map(List<String> values)
      Create a JSON map
      Parameters:
      values - key/value pairs [ key1,value1,key2,value2 ]
      Returns:
      the map object { key1:value1, key2:value2 }
    • mapAndQuote

      public static String mapAndQuote(List<String> values)
      _more_
      Parameters:
      values - _more_
      Returns:
      _more_
    • map

      public static String map(String[] values, boolean quoteValue)
      Create a JSON map
      Parameters:
      values - key/value pairs { key1,value1,key2,value2 }
      quoteValue - true to quote the values
      Returns:
      the map object { key1:value1, key2:value2 }
    • map

      public static String map(List<String> values, boolean quoteValue)
      Create a JSON map
      Parameters:
      values - key/value pairs [ key1,value1,key2,value2 ]
      quoteValue - true to quote the values
      Returns:
      the map object { key1:value1, key2:value2 }
    • list

      public static String list(String[] values)
      Create a JSON list from the array of strings
      Parameters:
      values - list of values { value1,value2,value3,value4 }
      Returns:
      the values as a JSON array [ value1,value2,value3,value4 ]
    • list

      public static String list(List values)
      Create a JSON list from the array of strings
      Parameters:
      values - list of values [ value1,value2,value3,value4 ]
      Returns:
      the values as a JSON array [ value1,value2,value3,value4 ]
    • mapKey

      public static String mapKey(String key)
      _more_
      Parameters:
      key - _more_
      Returns:
      _more_
    • mapOpen

      public static String mapOpen()
      _more_
      Returns:
      _more_
    • mapClose

      public static String mapClose()
      _more_
      Returns:
      _more_
    • listOpen

      public static String listOpen()
      _more_
      Returns:
      _more_
    • listClose

      public static String listClose()
      _more_
      Returns:
      _more_
    • list

      public static String list(List values, boolean quoteValue)
      Create a JSON list from the array of strings
      Parameters:
      values - list of values [ value1,value2,value3,value4 ]
      quoteValue - true to quote the values
      Returns:
      the values as a JSON array [ value1,value2,value3,value4 ]
    • tfoList

      public static String tfoList(List<TwoFacedObject> values)
      Create a list of JSON object from a list of TwoFacedObjects
      Parameters:
      values - the values
      Returns:
      the list [ {id:id1,label:label1},{id:id2,label:label2} ]
    • tfoList

      public static String tfoList(List<TwoFacedObject> values, String idKey, String labelKey)
      Create a list of JSON object from a list of TwoFacedObjects
      Parameters:
      values - the values
      idKey - the key for the TwoFacedObject ID
      labelKey - the key for the TwoFacedObject label
      Returns:
      the list [ {id:id1,label:label1},{id:id2,label:label2} ]
    • getString

      public static String getString(String s, boolean quote)
      Get a string
      Parameters:
      s - the string
      quote - true to quote
      Returns:
      the string
    • attr

      public static String attr(String name, double value)
      _more_
      Parameters:
      name - _more_
      value - _more_
      Returns:
      _more_
    • attr

      public static String attr(String name, long value)
      _more_
      Parameters:
      name - _more_
      value - _more_
      Returns:
      _more_
    • attr

      public static String attr(String name, String value)
      Create a JSON object attribute
      Parameters:
      name - the attribute name
      value - the attribute value
      Returns:
      the attribute as name:value
    • attr

      public static String attr(String name, String value, boolean quoteValue)
      Create a JSON object attribute
      Parameters:
      name - the attribute name
      value - the attribute value
      quoteValue - true to quote the name and value
      Returns:
      the attribute as name:value
    • quoteAttr

      public static void quoteAttr(List<String> items, String name, String value)
      quote the attribute value and add it to the list
      Parameters:
      items - the list of items
      name - the attribute name
      value - the attribute value
    • attr

      public static void attr(List<String> items, String name, String value)
      Make an attribute and add it to the list
      Parameters:
      items - the list of name/value pairs
      name - the attribute name
      value - the attribute value
    • formatNumber

      public static String formatNumber(double d)
      _more_
      Parameters:
      d - _more_
      Returns:
      _more_
    • quote

      public static String quote(String s)
      Quote a string
      Parameters:
      s - the string
      Returns:
      the quoted string
    • cleanString

      public static String cleanString(String aText)
      Clean a string of illegal JSON characters
      Parameters:
      aText - the string
      Returns:
      the cleaned string
    • main

      public static void main(String[] args)
      _more_
      Parameters:
      args - _more_