Snippets

From Java to JSON

  1. Creating a JSONObject from scratch
  2. Creating a JSONObject from a JSON formatted string
  3. Creating a JSONObject from a Map
  4. Creating a JSONObject from a JavaBean
  5. Creating a JSONArray from scratch
  6. Creating a JSONArray from a JSON formatted string
  7. Creating a JSONArray from a Collection
  8. Creating a JSONArray from an array
  9. JavaScript functions
  10. Exclude properties
  11. Exclude properties (with filters)

From JSON to Java

  1. JSONObject to DynaBean
  2. JSONObject to JavaBean
  3. JSONArray to List
  4. JSONArray to array
  5. JSONArray to array (type conversion)
  6. JSONObject to JavaBean, exclude properties with filters

From JSON to XML

  1. JSONObject to XML
  2. JSONObject to XML (no type hints)
  3. JSONObject to XML (with json prefix)
  4. JSONObject to XML (change node names)
  5. JSONArray to XML
  6. JSONArray to XML (no type hints)
  7. JSONArray to XML (with json prefix)
  8. Flatten JSONArray into parent

From XML to JSON

  1. XML to JSONObject

Groovy Support

  1. Using the JsonGroovyBuilder

JRuby Support

  1. Creating a JSONObject
  2. Append elements to JSONObject with << (array)
  3. Append elements to JSONObject with << (hash)

From Java to JSON

Creating a JSONObject from scratch

[Index|From Java to JSON]

Creating a JSONObject from a JSON formatted string

[Index|From Java to JSON]

Creating a JSONObject from a Map

[Index|From Java to JSON]

Creating a JSONObject from a JavaBean

[Index|From Java to JSON]

Creating a JSONArray from scratch

[Index|From Java to JSON]

Creating a JSONArray from a JSON formatted string

[Index|From Java to JSON]

Creating a JSONArray from a Collection

[Index|From Java to JSON]

Creating a JSONArray from an array

[Index|From Java to JSON]

JavaScript functions

[Index|From Java to JSON]

Exclude properties

[Index|From Java to JSON]

Exclude properties (with filters)

[Index|From Java to JSON]

From JSON to Java

JSONObject to DynaBean

[Index|From JSON to Java]

JSONObject to JavaBean

[Index|From JSON to Java]

JSONArray to List

[Index|From JSON to Java]

JSONArray to array

[Index|From JSON to Java]

JSONArray to array (type conversion)

[Index|From JSON to Java]

JSONObject to JavaBean, exclude properties with filters

[Index|From JSON to Java]

From JSON to XML

JSONObject to XML

[Index|From JSON to XML]

JSONObject to XML (no type hints)

[Index|From JSON to XML]

JSONObject to XML (with json prefix)

[Index|From JSON to XML]

JSONObject to XML (change node names)

[Index|From JSON to XML]

JSONArray to XML

[Index|From JSON to XML]

JSONArray to XML (no type hints)

[Index|From JSON to XML]

JSONArray to XML (with json prefix)

[Index|From JSON to XML]

Flatten JSONArray into parent

[Index|From JSON to XML]

From XML to JSON

XML to JSONObject

[Index|From XML to JSON]

Groovy Support

Using the JsonGroovyBuilder

The following snippets produce the same JSON output

[Index|Groovy Support]

JRuby Support

Creating a JSONObject

[Index|JRuby Support]

Append elements to JSONObject with << (array)

[Index|JRuby Support]

Append elements to JSONObject with << (hash)

[Index|JRuby Support]