@Override public String toString() { // Create a new json object JSONObject obj = new JSONObject(); obj.put("buildNumber", buildNumber); obj.put("download", download.toString()); // Return parsed json to string return obj.toJSONString(); }
@SuppressWarnings("unchecked") @Override public String toJSONString() { JSONArray jsonArray = new JSONArray(); for(String kw : keywords) { JSONObject data = new JSONObject(); data.put("name", kw); data.put("value", kw); jsonArray.add(data); } return jsonArray.toJSONString(); }
public Number connect(Map conf, TopologyContext context) throws IOException, NoOutputException { JSONObject setupInfo = new JSONObject(); setupInfo.put("pidDir", context.getPIDDir()); setupInfo.put("conf", conf); setupInfo.put("context", context); writeMessage(setupInfo); return (Number) ((JSONObject) readMessage()).get("pid"); }
@SuppressWarnings("unchecked") private void parseRBMMessage(JSONObject json) { String message = (String) json.get("message"); if (message.contains("(")) { json.put("process", message.substring(0, message.indexOf("("))); if (message.contains(":")) { json.put("message", message.substring(message.indexOf(":") + 2)); } } }
public JSONArray storeRecentSearch( String recentSearch ) { JSONArray recentSearches = getRecentSearches(); try { if ( recentSearch == null || recentSearches.contains( recentSearch ) ) { return recentSearches; } recentSearches.add( recentSearch ); if ( recentSearches.size() > 5 ) { recentSearches.remove( 0 ); } PropsUI props = PropsUI.getInstance(); String jsonValue = props.getRecentSearches(); JSONParser jsonParser = new JSONParser(); JSONObject jsonObject = jsonValue != null ? (JSONObject) jsonParser.parse( jsonValue ) : new JSONObject(); jsonObject.put( getLogin(), recentSearches ); props.setRecentSearches( jsonObject.toJSONString() ); } catch ( Exception e ) { e.printStackTrace(); } return recentSearches; }
@Override public JSONObject joinMessages(Map<String, Tuple> streamMessageMap, MessageGetStrategy messageGetStrategy) { JSONObject message = new JSONObject(); for (String key : streamMessageMap.keySet()) { Tuple tuple = streamMessageMap.get(key); JSONObject obj = (JSONObject) messageGetStrategy.get(tuple); message.putAll(obj); } List<Object> emptyKeys = new ArrayList<>(); for(Object key : message.keySet()) { Object value = message.get(key); if(value == null || value.toString().length() == 0) { emptyKeys.add(key); } } for(Object o : emptyKeys) { message.remove(o); } message.put(getClass().getSimpleName().toLowerCase() + ".joiner.ts", "" + System.currentTimeMillis()); return message; }
@SuppressWarnings("unchecked") private void addResult(JSONArray ja, SearchResult result) { JSONObject document = new JSONObject(); document.putAll(result.getFields()); document.put("docid", result.getDocId()); document.put("query_relevance_score", result.getScore()); for(Entry<Integer, Double> entry: result.getVariables().entrySet()) { document.put("variable_" + entry.getKey(), entry.getValue()); } for(Entry<String, String> entry: result.getCategories().entrySet()) { document.put("category_" + entry.getKey(), entry.getValue()); } ja.add(document); }
@SuppressWarnings( "unchecked" ) private void outPutRow( Object[] rowData ) throws KettleStepException { // We can now output an object data.jg = new JSONObject(); data.jg.put( data.realBlocName, data.ja ); String value = data.jg.toJSONString(); if ( data.outputValue && data.outputRowMeta != null ) { Object[] outputRowData = RowDataUtil.addValueData( rowData, data.inputRowMetaSize, value ); incrementLinesOutput(); putRow( data.outputRowMeta, outputRowData ); } if ( data.writeToFile && !data.ja.isEmpty() ) { // Open a file if ( !openNewFile() ) { throw new KettleStepException( BaseMessages.getString( PKG, "JsonOutput.Error.OpenNewFile", buildFilename() ) ); } // Write data to file try { data.writer.write( value ); } catch ( Exception e ) { throw new KettleStepException( BaseMessages.getString( PKG, "JsonOutput.Error.Writing" ), e ); } // Close file closeFile(); } // Data are safe data.rowsAreSafe = true; data.ja = new JSONArray(); }
@SuppressWarnings({"unchecked"}) public JSONObject getJSONObject() { JSONObject errorMessage = new JSONObject(); errorMessage.put(Constants.GUID, UUID.randomUUID().toString()); errorMessage.put(Constants.SENSOR_TYPE, "error"); if (sensorTypes.size() == 1) { errorMessage.put(ErrorFields.FAILED_SENSOR_TYPE.getName(), sensorTypes.iterator().next()); } else { errorMessage .put(ErrorFields.FAILED_SENSOR_TYPE.getName(), new JSONArray().addAll(sensorTypes)); } errorMessage.put(ErrorFields.ERROR_TYPE.getName(), errorType.getType()); addMessageString(errorMessage); addStacktrace(errorMessage); addTimestamp(errorMessage); addHostname(errorMessage); addRawMessages(errorMessage); addErrorHash(errorMessage); return errorMessage; }
/** {@inheritDoc} */ @Override JSONObject toJson() { JSONObject ret = super.toJson(); if (hasSingleAttribute()) { ret.put("attribute",attributes.get(0)); } else if (!hasAllAttributes()) { JSONArray attrs = new JSONArray(); attrs.addAll(attributes); ret.put("attribute",attrs); } if (path != null) { ret.put("path",path); } return ret; }
@SuppressWarnings( "unchecked" ) public String getPlugins() { List<PluginInterface> plugins = pluginRegistry.getPlugins( RepositoryPluginType.class ); JSONArray list = new JSONArray(); for ( PluginInterface pluginInterface : plugins ) { if ( !pluginInterface.getIds()[0].equals( "PentahoEnterpriseRepository" ) ) { JSONObject repoJSON = new JSONObject(); repoJSON.put( "id", pluginInterface.getIds()[ 0 ] ); repoJSON.put( "name", pluginInterface.getName() ); repoJSON.put( "description", pluginInterface.getDescription() ); list.add( repoJSON ); } } return list.toString(); }
public static void main(String[] args) { // convert Java to json JSONObject root = new JSONObject(); root.put("message", "Hi"); JSONObject place = new JSONObject(); place.put("name", "World!"); root.put("place", place); String json = root.toJSONString(); System.out.println(json); System.out.println(); // convert json to Java JSONObject obj = (JSONObject) JSONValue.parse(json); String message = (String) obj.get("message"); place = (JSONObject) obj.get("place"); String name = (String) place.get("name"); System.out.println(message + " " + name); } }
@Override public byte[] mapRecord(TridentTuple tuple) { JSONObject obj = new JSONObject(); if (this.columnFields != null) { for (String field : this.columnFields) { obj.put(field, tuple.getValueByField(field)); } } return obj.toJSONString().getBytes(); }
@SuppressWarnings("unchecked") private void parseOtherMessage(JSONObject json) { String message = (String) json.get("message"); if (message.contains("(")) { json.put("process", message.substring(0, message.indexOf("("))); if (message.contains(":")) { json.put("message", message.substring(message.indexOf(":") + 2)); } } } }
JSONObject jo = new JSONObject(); jo.put( outputField.getElementName(), data.inputRowMeta.getBoolean( row, data.fieldIndexes[i] ) ); break; case ValueMetaInterface.TYPE_INTEGER: jo.put( outputField.getElementName(), data.inputRowMeta.getInteger( row, data.fieldIndexes[i] ) ); break; case ValueMetaInterface.TYPE_NUMBER: jo.put( outputField.getElementName(), data.inputRowMeta.getNumber( row, data.fieldIndexes[i] ) ); break; case ValueMetaInterface.TYPE_BIGNUMBER: jo.put( outputField.getElementName(), data.inputRowMeta.getBigNumber( row, data.fieldIndexes[i] ) ); break; default: jo.put( outputField.getElementName(), data.inputRowMeta.getString( row, data.fieldIndexes[i] ) ); break; data.ja.add( jo );
private void createEmptyFile() { try { FileWriter fileWriter = new FileWriter(HISTORY_FILE); JSONObject root = new JSONObject(); root.put("messages", new JSONArray()); fileWriter.write(root.toJSONString()); fileWriter.flush(); fileWriter.close(); } catch (IOException e) { logger.error("Error during creating history file: ", e); } }
JSONObject obj = new JSONObject(); obj.put("name", this.getName()); obj.put("price", this.getPrice()); obj.put("description", this.getDescription()); obj.put("highlight", this.getHighlight()); obj.put("store", this.getStore()); obj.put("manufacturer", this.getManufacturer()); obj.put("lang", this.getLang()); obj.put("id", this.getId()); if(categories!=null) { JSONArray categoriesArray = new JSONArray(); for(String category : categories) { categoriesArray.add(category); obj.put("categories", categoriesArray); JSONArray tagsArray = new JSONArray(); for(String tag : tags) { tagsArray.add(tag); obj.put("tags", tagsArray);
JSONObject json = new JSONObject(); for ( Header header : headers ) { Object previousValue = json.get( header.getName() ); if ( previousValue == null ) { json.put( header.getName(), header.getValue() ); } else if ( previousValue instanceof List ) { List<String> list = (List<String>) previousValue; list.add( (String) previousValue ); list.add( header.getValue() ); json.put( header.getName(), list );