Class JSONEditor
- java.lang.Object
-
- edu.uiuc.ncsa.security.util.cli.AbstractEditor
-
- edu.uiuc.ncsa.security.util.cli.json_edit.JSONEditor
-
public class JSONEditor extends AbstractEditor
An editor for JSON objects. Mostly an experiment to see if this is viable for large JSON objects.Created by Jeff Gaynor
on 8/17/20 at 10:26 AM
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classJSONEditor.formatRecord
-
Field Summary
Fields Modifier and Type Field Description static StringADD_NODEstatic StringCHANGE_NODEstatic StringCURRENT_NODEstatic StringDELETE_NODEstatic StringFILE_FLAGstatic StringFILE_LOADstatic StringFILE_SAVEstatic StringFORMAT_TYPE_BOOLEANstatic StringFORMAT_TYPE_JSON_ARRAYstatic StringFORMAT_TYPE_JSON_OBJECTstatic StringFORMAT_TYPE_NULLstatic StringFORMAT_TYPE_NUMBERstatic StringFORMAT_TYPE_STRINGstatic StringFORMAT_TYPE_UNKNOWNstatic StringLIST_NODEstatic StringPRINT_RAW_FLAGprotected static intRC_CONTINUEprotected static intRC_EXITprotected static intRC_NO_OPprotected static intRC_OKstatic StringSET_NODE_VALUEstatic StringTREE_COMMANDprotected StringTREE_PIPEprotected StringTREE_PLUSprotected static StringTYPE_FLAGprotected static StringVALUE_FLAG-
Fields inherited from class edu.uiuc.ncsa.security.util.cli.AbstractEditor
HELP_COMMAND, isDone, PROMPT, QUIT_COMMAND, QUIT_COMMAND_LONG, VERBOSE_COMMAND, VERBOSE_COMMAND_LONG, verboseOn
-
-
Constructor Summary
Constructors Constructor Description JSONEditor()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected int_doAddNode(EditorInputLine eil)protected void_doChangeNode(EditorInputLine eil)protected void_doCurrentNode()protected int_doFileSave(EditorInputLine eil)protected int_doListNode(EditorInputLine eil)protected int_doVerbose(EditorInputLine eil)protected voidaddNodeHelp()protected ObjectconvertByType(String type, String rawValue)voidexecute()protected net.sf.json.JSONfileToJSON(String filename)protected StringfileToString(String fileName)protected StringformatScalar(Object object)protected StringformatSingleEntry(String key, Object obj)Entries look likenet.sf.json.JSONgetCurrentObject()protected StringgetEntryType(Object obj)protected voidinsertNode(net.sf.json.JSONObject json, net.sf.json.JSON node, String path)protected voidlistNodeHelp()static voidmain(String[] args)protected net.sf.json.JSONnavigate(String[] path)Navigates to the next to last component for a full path.protected voidprintArrayTree(String indent, String nodeName, net.sf.json.JSONArray array)protected voidprintObjectTree(String indent, String nodeName, net.sf.json.JSONObject jsonObject)protected voidprintRecords(List<JSONEditor.formatRecord> formatRecordList, boolean rawOnly)protected voidprintTypes()voidsetCurrentObject(net.sf.json.JSON currentObject)protected voidshowFileSaveHelp()protected voidwriteToFile(String filename, String contents)-
Methods inherited from class edu.uiuc.ncsa.security.util.cli.AbstractEditor
getIoInterface, readline, say, sayi, sayv, setIoInterface, showHelp, verboseHelp
-
-
-
-
Field Detail
-
CHANGE_NODE
public static final String CHANGE_NODE
- See Also:
- Constant Field Values
-
LIST_NODE
public static final String LIST_NODE
- See Also:
- Constant Field Values
-
CURRENT_NODE
public static final String CURRENT_NODE
- See Also:
- Constant Field Values
-
ADD_NODE
public static final String ADD_NODE
- See Also:
- Constant Field Values
-
DELETE_NODE
public static final String DELETE_NODE
- See Also:
- Constant Field Values
-
SET_NODE_VALUE
public static final String SET_NODE_VALUE
- See Also:
- Constant Field Values
-
TREE_COMMAND
public static final String TREE_COMMAND
- See Also:
- Constant Field Values
-
FILE_LOAD
public static final String FILE_LOAD
- See Also:
- Constant Field Values
-
FILE_SAVE
public static final String FILE_SAVE
- See Also:
- Constant Field Values
-
RC_CONTINUE
protected static int RC_CONTINUE
-
RC_EXIT
protected static int RC_EXIT
-
RC_OK
protected static int RC_OK
-
RC_NO_OP
protected static int RC_NO_OP
-
TREE_PIPE
protected String TREE_PIPE
-
TREE_PLUS
protected String TREE_PLUS
-
FILE_FLAG
public static final String FILE_FLAG
- See Also:
- Constant Field Values
-
TYPE_FLAG
protected static String TYPE_FLAG
-
VALUE_FLAG
protected static String VALUE_FLAG
-
PRINT_RAW_FLAG
public static final String PRINT_RAW_FLAG
- See Also:
- Constant Field Values
-
FORMAT_TYPE_JSON_OBJECT
public static final String FORMAT_TYPE_JSON_OBJECT
- See Also:
- Constant Field Values
-
FORMAT_TYPE_JSON_ARRAY
public static final String FORMAT_TYPE_JSON_ARRAY
- See Also:
- Constant Field Values
-
FORMAT_TYPE_BOOLEAN
public static final String FORMAT_TYPE_BOOLEAN
- See Also:
- Constant Field Values
-
FORMAT_TYPE_NUMBER
public static final String FORMAT_TYPE_NUMBER
- See Also:
- Constant Field Values
-
FORMAT_TYPE_STRING
public static final String FORMAT_TYPE_STRING
- See Also:
- Constant Field Values
-
FORMAT_TYPE_NULL
public static final String FORMAT_TYPE_NULL
- See Also:
- Constant Field Values
-
FORMAT_TYPE_UNKNOWN
public static final String FORMAT_TYPE_UNKNOWN
- See Also:
- Constant Field Values
-
-
Method Detail
-
getCurrentObject
public net.sf.json.JSON getCurrentObject()
-
setCurrentObject
public void setCurrentObject(net.sf.json.JSON currentObject)
-
execute
public void execute() throws Throwable- Overrides:
executein classAbstractEditor- Throws:
Throwable
-
showFileSaveHelp
protected void showFileSaveHelp()
-
writeToFile
protected void writeToFile(String filename, String contents) throws IOException
- Throws:
IOException
-
_doFileSave
protected int _doFileSave(EditorInputLine eil)
-
insertNode
protected void insertNode(net.sf.json.JSONObject json, net.sf.json.JSON node, String path)
-
fileToJSON
protected net.sf.json.JSON fileToJSON(String filename) throws IOException
- Throws:
IOException
-
fileToString
protected String fileToString(String fileName) throws IOException
- Throws:
IOException
-
printObjectTree
protected void printObjectTree(String indent, String nodeName, net.sf.json.JSONObject jsonObject)
-
printArrayTree
protected void printArrayTree(String indent, String nodeName, net.sf.json.JSONArray array)
-
addNodeHelp
protected void addNodeHelp()
-
_doAddNode
protected int _doAddNode(EditorInputLine eil)
-
listNodeHelp
protected void listNodeHelp()
-
navigate
protected net.sf.json.JSON navigate(String[] path)
Navigates to the next to last component for a full path. If this returns a null, then there was no such path- Parameters:
path-- Returns:
-
_doListNode
protected int _doListNode(EditorInputLine eil)
-
_doCurrentNode
protected void _doCurrentNode()
-
_doVerbose
protected int _doVerbose(EditorInputLine eil)
-
_doChangeNode
protected void _doChangeNode(EditorInputLine eil)
-
main
public static void main(String[] args)
-
printTypes
protected void printTypes()
-
formatSingleEntry
protected String formatSingleEntry(String key, Object obj)
Entries look likekey | type | entrytypes are+ = JSON object * = array b = boolean n = number s = string- Parameters:
obj-- Returns:
-
printRecords
protected void printRecords(List<JSONEditor.formatRecord> formatRecordList, boolean rawOnly)
-
-