public static void FromElement() { using (JsonDocument document = JsonDocument.Parse("[42]")) { JsonArray jArray = JsonArray.Create(document.RootElement); Assert.Equal(42, jArray[0].GetValue <int>()); } using (JsonDocument document = JsonDocument.Parse("null")) { JsonArray jArray = JsonArray.Create(document.RootElement); Assert.Null(jArray); } }
private void AddChild(JsonObject node, string propertyName, JsonElement element) { var options = new JsonNodeOptions { PropertyNameCaseInsensitive = Options.PropertyNameCaseInsensitive }; JsonNode?childNode = element.ValueKind == JsonValueKind.Object ? JsonObject.Create(element, options) : element.ValueKind == JsonValueKind.Array ? JsonArray.Create(element, options) : JsonValue.Create(element, options); node[propertyName] = childNode; }
public JsonObject ToJson() { var json = new JsonObject { { "Keys", new XNodeArray(Keys.Select(k => k.ToJson()).ToArray()) } }; if (AttributesToGet != null) { json.Add("AttributesToGet", JsonArray.Create(AttributesToGet)); } if (ConsistentRead) { json.Add("ConsistentRead", ConsistentRead); } return(json); }
public JsonObject ToJson() { var json = new JsonObject { { "Keys", Keys.ToNodeList() } }; if (AttributesToGet != null) { json.Add("AttributesToGet", JsonArray.Create(AttributesToGet)); } if (ConsistentRead) { json.Add("ConsistentRead", ConsistentRead); } return(json); }
public JsonObject ToJson() { var json = new JsonObject { { "TableName", TableName }, { "Key", Key.ToJson() }, }; if (ConsistentRead) { json.Add("ConsistentRead", ConsistentRead); } if (ReturnConsumedCapacity) { json.Add("ReturnConsumedCapacity", "TOTAL"); } if (AttributesToGet != null) { json.Add("AttributesToGet", JsonArray.Create(AttributesToGet)); } return(json); }
public static void FromElement_WrongNodeTypeThrows(string json) { using (JsonDocument document = JsonDocument.Parse(json)) Assert.Throws <InvalidOperationException>(() => JsonArray.Create(document.RootElement)); }