private void valueString(String s) { if (top instanceof JsonObject) ((JsonObject)top).put(key, s); else ((JsonArray)top).add(s); }
private void valueInteger(Integer i) { if (top instanceof JsonObject) ((JsonObject)top).put(key, i); else ((JsonArray)top).add(i); }
@Override public void finishPair(long currLine, long currCol) { if ( value == null ) throw new InternalErrorException("null for 'value' (bad finishPair() allignment)") ; String k = keys.pop(); JsonObject obj = objects.peek() ; if ( obj.hasKey(k) ) Log.warn("JSON", "Duplicate key '"+k+"' for object ["+currLine+","+currCol+"]") ; obj.put(k, value) ; value = null ; }
@Override public void finishPair(long currLine, long currCol) { if ( value == null ) throw new InternalErrorException("null for 'value' (bad finishPair() allignment)") ; String k = keys.pop(); JsonObject obj = objects.peek() ; if ( obj.hasKey(k) ) Log.warn("JSON", "Duplicate key '"+k+"' for object ["+currLine+","+currCol+"]") ; obj.put(k, value) ; value = null ; }
private void maybeObjectOrArray(JsonValue value) { if ( stack.size() == 0 ) // Error. return ; switch (stack.peek()) { case OBJECT : { String k = keys.pop() ; JsonObject obj = objects.peek() ; if ( obj.hasKey(k) ) Log.warn(this, "Duplicate key '" + k + "' for object") ; obj.put(k, value) ; return ; } case ARRAY : { arrays.peek().add(value) ; return ; } } }
private void maybeObjectOrArray(JsonValue value) { if ( stack.size() == 0 ) // Error. return ; switch (stack.peek()) { case OBJECT : { String k = keys.pop() ; JsonObject obj = objects.peek() ; if ( obj.hasKey(k) ) Log.warn(this, "Duplicate key '" + k + "' for object") ; obj.put(k, value) ; return ; } case ARRAY : { arrays.peek().add(value) ; return ; } } }
@Override public JSONWriterFacade value(boolean b) { try { if (top instanceof JsonObject) { ((JsonObject)top).put(key, b); } else { ((JsonArray)top).add(b); } } catch (JsonException e) { throw new EncodingException(e.getMessage(), e); } return this; }
@Override public JSONWriterFacade endObject() { if (! (top instanceof JsonObject)) { throw new EncodingException("endObject called on non object"); } JsonObject o = (JsonObject)top; if (stack.isEmpty()) return this; top = stack.pop(); key = keystack.pop(); if (top instanceof JsonObject) { try { ((JsonObject)top).put(key, o); } catch (JsonException e) { throw new EncodingException(e.getMessage(), e); } } else { ((JsonArray)top).add(o); } return this; }
@Override public JSONWriterFacade endArray() { if (! (top instanceof JsonArray)) { throw new EncodingException("endArray called on non array"); } JsonArray o = (JsonArray)top; if (stack.isEmpty()) return this; top = stack.pop(); key = keystack.pop(); if (top instanceof JsonObject) { try { ((JsonObject)top).put(key, o); } catch (JsonException e) { throw new EncodingException(e.getMessage(), e); } } else { ((JsonArray)top).add(o); } return this; }
@Override public JSONWriterFacade value(long l) { try { if (top instanceof JsonObject) { ((JsonObject)top).put(key, l); } else { ((JsonArray)top).add(l); } } catch (JsonException e) { throw new EncodingException(e.getMessage(), e); } return this; }
@Override public JsonObject next() { if (queryIterator == null) throw new NoSuchElementException(this.getClass() + ".next") ; try { Binding binding = queryIterator.next() ; JsonObject jsonObject = new JsonObject() ; for (String resultVar : resultVars) { Node n = binding.get(Var.alloc(resultVar)) ; JsonValue value = RDFTerm2Json.fromNode(n) ; jsonObject.put(resultVar, value); } return jsonObject ; } catch (NoSuchElementException ex) { close() ; throw ex ; } }
obj.put("x1", new JsonString("y")) ; obj.put("x2", JsonNumber.value(56)) ; obj.put("x2", JsonNumber.value(56)) ; JsonArray a = new JsonArray() ; a.add(JsonNumber.value(5)) ; a.add(new JsonBoolean(true)) ; a.add(new JsonBoolean(false)) ; obj.put("array", a) ; a = new JsonArray() ; a.add(JsonNumber.value(5)) ; obj.put("array2", a) ; obj.output(IndentedWriter.stdout) ; System.out.println() ;
if ( ! DPS.pspFile.equals(patchStore.getProvider().getShortName()) ) obj.put(F_LOG_TYPE, patchStore.getProvider().getShortName()); LOG.info(JSON.toStringFlat(obj)); try (OutputStream out = Files.newOutputStream(sourcePath.resolve(FileNames.DS_CONFIG))) {
@Test public void js_value_5() { JsonObject obj = new JsonObject() ; obj.put("a", JsonNumber.value(123)) ; read("{ \"a\": 123 }", obj) ; }
@Test public void js_map_ext_1() { JsonObject obj = new JsonObject() ; obj.put("abc", JsonNumber.value(123)) ; writeRead(obj) ; // Use of key. read("{abc: 123}", obj) ; } }
@Test public void js_value_8() { JsonObject obj = new JsonObject() ; JsonArray array = new JsonArray() ; array.add(JsonNumber.value(123)) ; obj.put("a", array) ; read("{ \"a\" : [ 123 ] }", obj) ; }
@Override public JsonArray execJson() { checkNotClosed() ; if ( ! query.isJsonType() ) throw new QueryExecException("Attempt to get a JSON result from a " + labelForQuery(query)+" query") ; startQueryIterator() ; JsonArray jsonArray = new JsonArray() ; List<String> resultVars = query.getResultVars() ; while (queryIterator.hasNext()) { Binding binding = queryIterator.next() ; JsonObject jsonObject = new JsonObject() ; for (String resultVar : resultVars) { Node n = binding.get(Var.alloc(resultVar)) ; JsonValue value = RDFTerm2Json.fromNode(n) ; jsonObject.put(resultVar, value) ; } jsonArray.add(jsonObject) ; } return jsonArray ; }
frame.put("@type", ns +"Person"); jenaCtx.set(JsonLDWriter.JSONLD_FRAME, frame.toString()); String jsonld = toString(m, RDFFormat.JSONLD_FRAME_PRETTY, jenaCtx); frame.put("http://schema.org/jobTitle", new JsonObject()); jenaCtx.set(JsonLDWriter.JSONLD_FRAME, JsonUtils.fromString(frame.toString())); jsonld = toString(m, RDFFormat.JSONLD_FRAME_FLAT, jenaCtx);