this my structure
{
"_id": ObjectId,//PropertyTrackingModel Object
"Items": [{
"Date": "2018-01-29",
"Tracks": [{
"ModifiedDate": "2018-06-29T10:21:03.1268154+00:00"
}]
}, {
"Date": "2018-08-29",
"Tracks": [{
"ModifiedDate": "2018-08-29T10:21:03.1268154+00:00"
}]
}]
}
so i want insert New Tracks in date=="2018-08-29" collection
and it like daily data
finaly i need
{
"_id": ObjectId,//PropertyTrackingModel Object
"Items": [{
"Date": "2018-01-29",
"Tracks": [{
"ModifiedDate": "2018-06-29T10:21:03.1268154+00:00"
}]
}, {
"Date": "2018-08-29",
"Tracks": [{
"ModifiedDate": "2018-08-29T10:21:03.1268154+00:00"
},
{
"ModifiedDate": "2018-08-29T10:21:03.1268154+00:00"
}]
}]
}
thank all of you
bast way using C# mongo driver function
Related
Delete a specific node from all the available documents in a bucket
Is it possible to delete an element from the children array based on the Id from the below sample document using .NET SDK for Couchbase in C#?
i.e. I need to delete all the details of Id=100( delete the entire element in the children array).
I can achieve it using N1QL. N1QL performance is slow when there are thousands of document involved in couchbase
{
"results": [{
"tutorial": {
"type": "contact",
"title": "Mr.",
"fname": "Ian",
"lname": "Taylor",
"age": 56,
"email": "ian#gmail.com",
"children": [{
"Id": "100",
"Details": [{
"fname": "Abama",
"age": 17,
"gender": "F"
}]
},
{
"Id": "101",
"Details": [{
"fname": "Alex",
"age": 17,
"gender": "M"
}]
}
],
"hobbies": [
"golf",
"surfing"
],
"relation": "cousin"
}
}]
}
How can I extract items from nested Json Array using Newtonsoft.Json functions or methods? I have a Json like this
{
"Bounds": {
"TextLength": 1379
},
"DocumentTypeName": "Invoice",
"DocumentTypeField": {
"Value": "Invoice",
"Confidence": 1
},
"Fields": [
{
"FieldId": "RPA.DocumentUnderstanding.Invoice.LineItems",
"FieldName": "Line Items",
"Values": [
{
"Components": [
{
"FieldId": "RPA.DocumentUnderstanding.Invoice.LineItems.Body",
"FieldName": "Body",
"Values": [
{
"Components": [
{
"FieldId": "RPA.DocumentUnderstanding.Invoice.LineItems.Item",
"FieldName": "Item",
"Values": [
{
"Components": [],
"Value": "Film 4C for the publication \"Racing World\" Visual: PNSP 02 05 Ref. 2004/021 Graphic designer honoraries 560010",
"Confidence": 0.962736368
}
]
},
{
"FieldId": "RPA.DocumentUnderstanding.Invoice.LineItems.UnitPrice",
"FieldName": "Unit Price",
"Values": [
{
"Components": [],
"Value": "400.00",
"Confidence": 0.9779528
}
]
}
],
"Confidence": 0.9432406
}]}],
"Confidence": 0.920952857}]}]}
and I want to extract the red highlighted fields from it.
Any help will be much appreciated.
Thanks
Since not deserializing is not a requirement you can do that. Just create C# object that has the exact same structure as your JSON and then do
var yourObject = JsonConvert.DeserializeObject<YourCSharpClassHere>(yourJsonString);
Then it's just a simple matter of getting the values
var fieldName = yourObject.Values[0].Components[0].Values[0].Components[0].FieldName
You can use JSON Query
Example
var fieldNames = o.SelectTokens("Values[*].Components[*].Values[*].Components[*].FieldName");
I have all values from aspx page. now I want to prepare following json values by picking up from the control values of aspx where user has inputted and want to submit to other application in same format.For that below is the example I want to make exact copy as like below.
var tempk = {
"requestTypeCode": "PRE_DETERMINATION",
"billingProvider": {
"npi": "1234567893",
"ein": "111222333",
"payerAssignedProviderId": "XYZ321"
},
"patient": {
"relationshipCode": "01",
"lastName": "Smith",
"firstName": "Bob",
"stateCode": "FL",
"birthDate": "1980-02-12",
"genderCode": "M"
},
"payer": {
"id": "BCBSF"
},
"submitter": {
"id": "123456789",
"lastName": "SUBMITTER"
},
"subscriber": {
"memberId": "JDH001",
"groupName": "ASDF 1-2",
"groupNumber": "12312412"
},
"claimInformation": {
"placeOfServiceCode": "11",
"diagnoses": [
{
"qualifierCode": "ABK",
"code": "J3089"
}
],
"serviceLines": [
{
"procedureCode": "92523",
"quantity": "100",
"amount": "250",
"fromDate": "2016-05-10"
}
]
}
}
Can you assist me how with the C# code will achieve?
You can use Newtonsoft.Json from nuget
http://www.newtonsoft.com/json
I want to extract all IDs from the below object using c#.
in need of extracting a response value in a visual studio webtest.
The JSON is obtained using extract event.
{
"d": [
{
"__type": "QuestionZoneEditor.Entities.QuestionTag",
"Id": 2080,
"Name": "01",
"Items": [
"1a",
"1b",
"1c",
"1d"
]
},
{
"__type": "QuestionZoneEditor.Entities.QuestionTag",
"Id": 2081,
"Name": "02",
"Items": [
"2a(i)",
"2a(ii)",
"2b",
"2c"
]
},
{
"__type": "QuestionZoneEditor.Entities.QuestionTag",
"Id": 2082,
"Name": "03",
"Items": [
"3a",
"3b",
"3c"
]
}
}
]
}
Deserialize it to JObject after that take all JObject from the JArray and print the Id
var result = JsonConvert.DeserializeObject<JObject>(json);
foreach(JObject obj in result["d"])
{
Console.WriteLine(obj["Id"]);
}
Full example: dotNetFiddle
I have a problem with this JSON to get the second level in JArray:
{
"Level1": {
"Level2": [{
"id": "Chart",
"Box": [{
"id": "1",
"value": "10"
},{
"id": "2",
"value": "20"
}]
}]
}
}
And I want to get completly the level 2 like Array in this way:
JArray contasdasd = _jsonMaster["Level1"]["Level2"] as JArray;
I get :
{
"id": "Chart",
"Box": [{
"id": "1",
"value": "10"
},{
"id": "2",
"value": "20"
}]
}
and I want:
"Level2": [{
"id": "Chart",
"Box": [{
"id": "1",
"value": "10"
},{
"id": "2",
"value": "20"
}]
}]
Is there any way to get the level 2 ?
Surely you just do
var level1 = _jsonMaster["Level1"];
The problem is that you've gone one level too far.
The object you are interested in "Level2": [...] is not a JArray itself but is a JProperty. You can get it by searching properties of Level1 but keep in mind you will now have a JProperty rather than a JArray. The Value of that result will be the JArray you were getting in your current code.
JProperty contasdasd = _jsonMaster["Level1"].First(o => (o as JProperty).Name == "Level2") as JProperty;
Console.WriteLine(contasdasd.ToString()); // Will be what you are looking for
Console.WriteLine(contasdasd.GetType()); // Will return JProperty
Console.WriteLine(contasdasd.Value.GetType()); // Will return JArray