1 /* 2 * Copyright 2002-2009 the original author or authors. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package net.sf.json; 17 18 import java.io.Writer; 19 import java.io.Serializable; 20 21 /** 22 * Marker interface, identifies a valid JSON value.<br> 23 * A JSON value may be a {@link JSONObject}, a {@link JSONArray} or a 24 * {@link JSONNull}. 25 * 26 * @author Andres Almiray <aalmiray@users.sourceforge.net> 27 */ 28 public interface JSON extends Serializable { 29 /** 30 * Returns true if this object is a JSONArray, false otherwise. 31 */ 32 boolean isArray(); 33 34 /** 35 * Returns true if this object has no elements or keys. 36 * 37 * @throws JSONException if called on a 'null' object 38 */ 39 boolean isEmpty(); 40 41 /** 42 * Returns the number of properties in an object or the size of the array. 43 * 44 * @return the size of an json object or array 45 * @throws JSONException if called on a 'null' object 46 */ 47 int size(); 48 49 /** 50 * Make a prettyprinted JSON text. 51 * <p> 52 * Warning: This method assumes that the data structure is acyclical. 53 * 54 * @param indentFactor The number of spaces to add to each level of 55 * indentation. 56 * @return a printable, displayable, portable, transmittable representation 57 * of the object, beginning with <code>{</code> <small>(left 58 * brace)</small> and ending with <code>}</code> <small>(right 59 * brace)</small>. 60 * @throws JSONException If the object contains an invalid number. 61 */ 62 String toString( int indentFactor ); 63 64 /** 65 * Make a prettyprinted JSON text. 66 * <p> 67 * Warning: This method assumes that the data structure is acyclical. 68 * 69 * @param indentFactor The number of spaces to add to each level of 70 * indentation. 71 * @param indent The indentation of the top level. 72 * @return a printable, displayable, transmittable representation of the 73 * object, beginning with <code>{</code> <small>(left brace)</small> 74 * and ending with <code>}</code> <small>(right brace)</small>. 75 * @throws JSONException If the object contains an invalid number. 76 */ 77 String toString( int indentFactor, int indent ); 78 79 /** 80 * Write the contents as JSON text to a writer. For compactness, no 81 * whitespace is added. 82 * <p> 83 * Warning: This method assumes that the data structure is acyclical. 84 * 85 * @return The writer. 86 * @throws JSONException 87 */ 88 Writer write( Writer writer ); 89 }