I'm trying to query DocumentDB by the following attribute
"Loop": [
{
"#LoopId": "0204",
"#Name": "Order Information Detail",
"OID": {
"OID01": null,
"OID02": "1NN***"
}
},
{
"#LoopId": "0210",
"#Name": "Quantity Information",
"QTY": {
"#comment": [],
"QTY01": {
"#text": "H9"
},
"QTY02": "10",
"QTY03": null,
"QTY04": "Pallets"
}]
using the Query
SELECT * FROM c WHERE c.Loop[0].OID.OID02="1NN***";
however the same document has another attribute Loop in it:
"Loop": [
{
"#LoopId": "0100",
"#Name": "Party Identification",
"N1": {
"#comment": [],
"N101": {
"#text": "CA"
},
"N102": "BN*********",
"N103": {
"#text": "2"
},
"N104": "B***"
}
},
{
"#LoopId": "0100",
"#Name": "Party Identification",
"N1": {
"#comment": [],
"N101": {
"#text": "SF"
},
"N102": "*****"
}]
is there anyway around this because I need to get the information by OID
thanks in advance
Can you try doing this query, as I think each "row" in the Loop array is a different Loop object:
SELECT * FROM Loop c WHERE c.OID.OID02 = "1NN***";
Related
Im using C# to write GraphQL queries and execute them
i created the schema and everything works fine i get the data back exactly as i want,
but the first letter of the name of the properties gets changed from a capital letter to a small letter.
this is my schema code,
var schema = Schema.For(#"
type user {
Indx: Int,
UserName: String,
Password: String
}
type Query {
users: [user]
}
",s=>s.Types.Include<Query>());
this is the execution code, this execution method works fine returns all the data i want from my tables but instead of returning property names with first letter capitalized it returns property names with first letter small.
var json = schema.ExecuteAsync( s => { s.Query = "{ users {indx,userName,password} }"; });
this is the result I get:
{
"data": {
"users": [
{
"indx": 593,
"userName": "string",
"password": "string"
},
{
"indx": 540,
"userName": "new test user",
"password": "1234"
},
{
"indx": 598,
"userName": "wolv",
"password": "1234"
}
]
}
}
if i change the execution to as follows :
var json = schema.ExecuteAsync( s => { s.Query = "{ users {Indx,UserName,Password} }"; });
i get an error in return:
{
"errors": [
{
"message": "Cannot query field \u0027Indx\u0027 on type \u0027user\u0027. Did you mean \u0027indx\u0027?",
"locations": [
{
"line": 1,
"column": 10
}
],
"extensions": {
"code": "FIELDS_ON_CORRECT_TYPE",
"codes": [
"FIELDS_ON_CORRECT_TYPE"
],
"number": "5.3.1"
}
},
{
"message": "Cannot query field \u0027UserName\u0027 on type \u0027user\u0027. Did you mean \u0027userName\u0027?",
"locations": [
{
"line": 1,
"column": 15
}
],
"extensions": {
"code": "FIELDS_ON_CORRECT_TYPE",
"codes": [
"FIELDS_ON_CORRECT_TYPE"
],
"number": "5.3.1"
}
},
{
"message": "Cannot query field \u0027Password\u0027 on type \u0027user\u0027. Did you mean \u0027password\u0027?",
"locations": [
{
"line": 1,
"column": 24
}
],
"extensions": {
"code": "FIELDS_ON_CORRECT_TYPE",
"codes": [
"FIELDS_ON_CORRECT_TYPE"
],
"number": "5.3.1"
}
}
]
}
I want the data to be returned like this:
{
"data": {
"users": [
{
"Indx": 593,
"UserName": "string",
"Password": "string"
},
{
"Indx": 540,
"UserName": "new test user",
"Password": "1234"
},
{
"Indx": 598,
"UserName": "wolv",
"Password": "1234"
}
]
}
}
any ideas ?
could anyone help me extract the specific value for [downloads][csv][href] out of the following json string please?
{
"#context": "https://cdn.ons.gov.uk/assets/json-ld/context.json",
"alerts": [],
"collection_id": "cmdr",
"dimensions": [
various dimensions here
],
"downloads": {
"csv": {
"href": "https://download.beta.ons.gov.uk/downloads/datasets/regional-gdp-by-year/editions/time-series/versions/4.csv",
"size": "568021"
},
"csvw": {
"href": "ref",
"size": "1903"
},
"xls": {
"href": "ref",
"size": "80768"
}
},
"edition": "time-series",
"id": "5c",
"links": {
"dataset": {
"href": "ref",
"id": "regional-gdp-by-year"
},
"edition": {
"href": "ref",
"id": "time-series"
},
"self": {
"href": "ref"
}
},
"release_date": "2021",
"state": "published",
"usage_notes": [],
"version": 4
}
the current code I am using returns nothing:
var labels = JObject.Parse(observationsJson)["downloads"];
var results = labels.Select(data => new
{
label = (string)data["href"]
});
foreach (var item in results)
{
csvDownloadAddress = item.label;
}
If there is another method rather than using linq then I am open to suggestions.
Sorry if this is a dumb quest, my experience with linq and json is very limited.
thank you for your help.
You have JSON Path, that can be used to select specific element(s) from the JSON string.
see Newtonsoft example, or you can use this JsonPath Nuget package.
The JsonPath Nuget can be used like below,
var input = "$.downloads.csv.href";
var path = JsonPath.Parse(input);
var hrefVal = path.Evaluate(jsonStr);
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'm having trouble querying nested objects in DocumentDB. I have no control over the format of the data. Let's say an object looks like this in DocumentDB:
{
"SCHEMA_ID": {
"PROJECT": "A",
"MODEL": "B",
"GUID":"A GUID"
},
"STATE": {
"Active": "True"
},
"OBJECTS": {
"OBJECT": [
{
"ATTR_VALS": {
"NAME": "Header",
"ID": "0",
"VALUE": [
{
"NAME": "JobId",
"VAL": "1011656"
},
{
"NAM": "Region",
"VAL": "West Coast"
}
]
}
},
{
"ATTR_VALS": {
"NAME": "SampleData",
"ID": "0",
"VALUE": [
{
"NAME": "Height",
"VAL": "5"
},
{
"NAM": "Length",
"VAL": "3"
}
]
}
}
]
}
}
I want to find all the objects that have a 'ATTR_VALS' = 'SampleData' and where those items have a 'Height'=5
So Far I have:
SELECT test.GUID
FROM test
join OBJECTS in test.OBJECTS
join OBJECT in OBJECTS
join ATTR_VALS in OBJECT
join VALUE in ATTR_VALS
WHERE ATTR_VALS.NAME = 'SampleData' AND VALUE.NAME='Height' AND VALUE.VAL='5'
But this doesn't work, and returns no results. Thanks!
The query must be:
SELECT test.SCHEMA_ID.GUID
FROM test
join OBJ in test.OBJECTS.OBJECT
join VAL in OBJ.ATTR_VALS["VALUE"]
WHERE OBJ.ATTR_VALS.NAME = "SampleData" AND VAL.NAME='Height' AND VAL.VAL='5'
A couple things I changed:
JOIN must be performed against arrays, not objects. Objects can be expanded using the “.” Operator
VALUE is a special keyword and must be escaped
Small typo in the projection clause missing SCHEMA_ID