JSONXML - hosted at sourceforge.net

JSONXML library is implemented trying to keep it as generic as possible. It uses hierarchy of classes providing generalized functionality most of which are used both in parsing and in formatting process. briefly these are:
  • Path - hierarchical structure elements may be accessed using simple path syntax: "name/name[idx]/name[idx]/name". Path allows numeric and textual indexes and provides set of methods to simplify its analysis and conversions.
  • Formats - locale/time-zone specific formatter/parser of scalar values (numbers, dates). Provides possibility to try several format variants on parsing. By overriding it context-specific (e.g. depending on path) conversions may be applied.
  • ObjectsRegistry - tool used to accumulate processed items and resolve cross-referencing problems.
  • ReflectiveBuilder - tool used to access Java object data reflectively on formatting and to restore objects on parsing. Also it resolves problem of Map serialization/deserialization by applying special lossless formatting. Default implementation uses getters/setters only. Any other strategy (e.g. fields, annotations, serialization-based etc. may be easily applied via extension(s)).
  • StructureProcessingContext - collect previously mentioned and other tools to provide single access point AND to allow replacement with user-defined extensions.
  • Utilities - place to gather any non-specific static methods/classes.
    Notice Utilities.NonResizableListForArray class that provides list-like access to any array (object or primitive). NOTE: this class is available starting from version 1.1 only.
Actual entry point to JSONXML library are basic classes:
  • Formatter - formatter implementation with shortcut methods for XML and JSON outputs.
  • Parser - shortcut methods to parse JSON and XML texts into Java objects.
  • Comparer - implementation of comparator of 2 java objects. Uses same structure scanning mechanisms as parser/formatter.
As example there're provided command-line tools:
  • converter - accepts file or URL, tries to parse it as XML or JSON and writes it to standard output in desired format (JSON, XML, Dump)
  • diff - accepts 2 input sources (file or URL, may be mixed), parses as XML or JSON and compares them. the difference is written to standard output in desired format.
When started to work with JSON I've used various parsers/formatters for Java. Gradually I've gathered a number of limitations common to all or some of them. As a result the following requirements to JSON parser/formatter (for Java) were formulated:
  1. MUST implement specification published at json.org
  2. MUST keep order of named object elements
  3. MUST support reflection to save/restore Java objects
  4. MUST accept Reader for input and Writer for output
  5. MUST be licensed with minimal restrictions - Apache License 2.0 seems optimal.
  6. MUST be distributed as single JAR and via maven repositories.
  7. SHOULD allow "loose" syntax (e.g. use of quoted/unquoted names, double or single quoted strings)
  8. SHOULD allow transparent conversion of JSON to XML and vice versa
  9. SHOULD provide means of flexible comparison of structures
  10. SHOULD support virtually any Java object by working around known "features" like stack overflow in collections with cross-references.
  11. SHOULD allow easy and reliable customization via extensions at different code levels
  12. SHOULD have no or minimal dependencies on 3rd party solutions (keep as "pure java")

Plans for future releases:

  • Extend reflection support to use known annotation "systems":
    • J2EE entities
    • xstream
    • ???
  • Visual tool for structure browsing/comparison. (NOTE: preliminary experiments available as JSONViewer sub-project, see SVN)
  • Refactorying
    • Move most generic classes to separate library/project (like Path, Utilities, etc.)
  • Support "properties"-like formats
  • Support YUML