How to validated pointer in json.net? - json.net

Hello I have the following scenario:
JSON object:
{
"$id": "1",
"someProp": "123",
"children": [{
"$id": "2",
"$type": "ClassB",
"Parent": {
"$ref": "1"
}
}]
}
JSON schema :
{
"id": "ClassA",
"required": true,
"type": [
"object",
"null"
],
"properties": {
"someProp": {
"required": true,
"type": [
"string",
"null"
]
},
"children": {
"id": "List<Child>",
"required": true,
"type": [
"array",
"null"
],
"items": {
"id": "Child",
"type": [
"object",
"null"
],
"properties": {
"id": {
"required": true,
"type": "integer"
},
"parent": {
"$ref": "ClassA"
}
}
}
}
}
}
I have a complex object who has reference loops, so I have configured json.net to make reference when the object is serialized. Everything is working as expected I can serialize and deserialize the object, but when I am validating the JSON object with the above schema I got the following error :
Required properties are missing from object : "someProp", path :
object.Children[0].parent
And that is correct how can make the schema look at the reference JSON object ?

Problem is with the "id" property of an object inside children array
"properties": {
"id": {
"required": true,
"type": "integer"
},
"parent": {
"$ref": "ClassA"
}
}
You are saying id requires to have property "id" and you don't have that property inside object, either changes "id" to "$id" or remove it from property list to satisfy schema.
"properties": {
"$id": {
"required": true,
"type": "integer"
},
"parent": {
"$ref": "ClassA"
}
}
Also make sure you have "id" / "$id" integer value, i.e.
"$id":2 not "$id":"2"

Related

JSON path help required for a request

I am new at JSON path request and I have a quite complex request to build.
I work with a JSOn strusture having 2 arrays like this example :
{
"WideXml": {
"Guid": "9cf379c5-dc12-4a63-922a-d242efe9a777",
"ApplicationGuid": "24df8af4-58c2-40dd-8ce8-70becb2df96f",
"Action": "Approval",
"Values": {
"Date": {
"TimeStamp": "2021-11-23T04:00:00Z",
"Value": [{
"Guid": "9c64fb06-60f5-4541-a006-3a92ac576e13",
"Value": "6.7169265747070313",
"Unit": "t",
"UserFields": {
"Field": [{
"Value": "131",
"Key": "BWART"
},
{
"Value": "14702-00-BULK",
"Key": "MATNR"
}
]
}
},
{
"Guid": "6c048d70-1521-4fa1-a462-669730d6b1ed",
"Value": "84.824371337890625",
"Unit": "t",
"UserFields": {
"Field": [{
"Value": "261",
"Key": "BWART"
}, {
"Value": "14366-00-WA0R",
"Key": "MATNR"
}]
}
}
]
}
}
}
}
I need to find the "MATNR" code by searching with Key = 'BWART' and Value = '131'.
I can find the Field document by the request
$.WideXml.Values.Date.Value[*].UserFields.Field[?(#.Key=='BWART' && #.Value=='131')]
But I don't manage to build the query to get the MATNR after having this result...
Can someone help?
Regards.
if the key BWART is always at the same index position i.e 0 in this example, you can try the expression
$.WideXml.Values.Date.Value[?(#.UserFields.Field[0].Key== "BWART" && #.UserFields.Field[0].Value == "131")].UserFields.Field[*]

The language expression property '0' can't be evaluated, property name must be a string - ARM Template error while adding Key Vault access policy

I've been working on an issue and seem to be stuck, so asking on so in case anyone can help.
To describe the issue, I've got an existing Azure Key Vault setup, and wish to add a number of access policies to this resource group. It needs to be conditional as if the function name is "false" then that function should not be added to key vault access policy.
variable section:
"variables": {
"functionAccess": {
"value": [
{
"name": "[parameters('Function_1')]"
},
{
"name": "[parameters('Function_2')]"
},
{
"name": "[parameters('Function_3')]"
}
]
}
}
My Template :
{
"apiVersion": "2016-10-01",
"condition": "[not(equals(variables('functionAccess')[CopyIndex()].name, 'false'))]",
"copy": {
"batchSize": 1,
"count": "[length(variables('functionAccess'))]",
"mode": "Serial",
"name": "accessPolicies"
},
"name": "[concat(parameters('KeyVault_Name'), '/add')]",
"properties": {
"accessPolicies": [
{
"tenantId": "[subscription().tenantId]",
"objectId": "[if(not(equals(variables('functionAccess')[CopyIndex()].name, 'false')), reference(concat('Microsoft.Web/sites/', variables('functionAccess')[CopyIndex()].name), '2016-08-01', 'Full').identity.principalId, json('null'))]",
"permissions": {
"keys": [
"get",
"list"
],
"secrets": [
"get",
"list"
],
"certificates": [
"get",
"list"
]
}
}
]
},
"type": "Microsoft.KeyVault/vaults/accessPolicies"
}
When I deploy my ARM template for the azure key vault I got this error message:
The language expression property '0' can't be evaluated, property name must be a string.
also tried below, but same error:
{
"apiVersion": "2018-02-14",
"name": "[concat(parameters('KeyVault_Name'), '/add')]",
"properties": {
"copy": [
{
"batchSize": 1,
"count": "[length(variables('functionAccess'))]",
"mode": "serial",
"name": "accessPolicies",
"input": {
"condition": "[not(equals(variables('functionAccess')[copyIndex('accessPolicies')].name, 'false'))]",
"tenantId": "[subscription().tenantId]",
"objectId": "[if(not(equals(variables('functionAccess')[copyIndex('accessPolicies')].name, 'false')), reference(concat('Microsoft.Web/sites/', variables('functionAccess')[copyIndex('accessPolicies')].name), '2016-08-01', 'Full').identity.principalId, json('null'))]",
"permissions": {
"keys": [
"get",
"list"
],
"secrets": [
"get",
"list"
],
"certificates": [
"get",
"list"
]
}
}
}
]
},
"type": "Microsoft.KeyVault/vaults/accessPolicies"
}
There are a few options for dealing with filtering an array for copy operation. I deploy my ARM templates from PowerShell scripts and use PowerShell to setup parameter values. When I need special logic handle different inputs for different environments, I let PowerShell handle it.
If you must handle the filtering in ARM and you have the option to input a CSV list of functions, then perhaps the following will work. You can then use the functionAccessArray to iterate over in the copy operation.
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
},
"variables": {
"functionAccessCsv": "Function-0,Function-1,false,Function-4,false,Function-6,Function-7",
"functionAccessFiltered": "[replace(replace(variables('functionAccessCsv'), 'false', ''), ',,', ',')]",
"functionAccessArray": "[split(variables('functionAccessFiltered'), ',')]"
},
"resources": [
],
"outputs": {
"functionAccessCsvFiltered": {
"type": "string",
"value": "[variables('functionAccessFiltered')]"
},
"functionAccessArray": {
"type": "array",
"value": "[variables('functionAccessArray')]"
}
}
}
The result:
I just had the same issue. By using an array parameter with a default value instead of a variable, I got it to work.
"parameters": {
"functionAccess": {
"type": "array",
"defaultValue": [
"value1",
"value2",
"value3"
]
}
}

How Can I group by Gremlin Server (Titan 1.0) Response on Basis of Vertex Id?

I'm trying following query :
g.V(835776).out('Follow').in('WallPost').order().by('PostedTimeLong', decr).range(0,2)
and I'm getting following response :
{
"requestId": "524462bc-5e46-40bf-aafd-64d00351dc87",
"status": {
"message": "",
"code": 200,
"attributes": { }
},
"result": {
"data": [
{
"id": 1745112,
"label": "Post",
"type": "vertex",
"properties": {
"PostImage": [
{
"id": "sd97-11ejc-2wat",
"value": ""
}
],
"PostedByUser": [
{
"id": "sc2j-11ejc-2txh",
"value": "orbitpage#gmail.com"
}
],
"PostedTime": [
{
"id": "scgr-11ejc-2upx",
"value": "2016-06-19T09:17:27.6791521Z"
}
],
"PostMessage": [
{
"id": "sbob-11ejc-2t51",
"value": "Hello #[tag:Urnotice_Profile|835776|1] , #[tag:Abhinav_Srivastava|872488|1] and #[tag:Rituraj_Rathore|839840|1]"
}
],
"PostedTimeLong": [
{
"id": "scuz-11ejc-2vid",
"value": 636019246476802029
}
]
}
},
{
"id": 1745112,
"label": "Post",
"type": "vertex",
"properties": {
"PostImage": [
{
"id": "sd97-11ejc-2wat",
"value": ""
}
],
"PostedByUser": [
{
"id": "sc2j-11ejc-2txh",
"value": "orbitpage#gmail.com"
}
],
"PostedTime": [
{
"id": "scgr-11ejc-2upx",
"value": "2016-06-19T09:17:27.6791521Z"
}
],
"PostMessage": [
{
"id": "sbob-11ejc-2t51",
"value": "Hello #[tag:Urnotice_Profile|835776|1] , #[tag:Abhinav_Srivastava|872488|1] and #[tag:Rituraj_Rathore|839840|1]"
}
],
"PostedTimeLong": [
{
"id": "scuz-11ejc-2vid",
"value": 636019246476802029
}
]
}
}
],
"meta": { }
}
}
since same post is posted on two different Id's it is coming twice in response. I want to group by response on basis of vertex id ( both have same vertex id. or i just want to get one object out of them as both are same only.
I've tried following queries but nothing worked for me :
g.V(835776).out('Follow').in('WallPost').groupBy{it.id}.order().by('PostedTimeLong', decr).range(0,3)
g.V(835776).out('Follow').in('WallPost').group().by(id).order().by('PostedTimeLong', decr).range(0,3)
How can I group by the result on basis of vertex id.
The query
g.V(835776).out('Follow').in('WallPost').group().by(id).order().by('PostedTimeLong', decr).range(0,3)
should work, although order().by() and range() will have no effect. However, I don'tthink you really want to group(), you more likely want to dedup():
g.V(835776).out('Follow').in('WallPost').dedup().order().by('PostedTimeLong', decr).limit(3)

IODocs : First Object inside Array Doesn't have a tag name

I want to add a objects inside a array. I have to set a name for that object like
"identifiers": [
"IDENTIFIER": {
"primary": true
}
]
Here "IDENTIFIER" is the object name. But the first object inside array always created as a empty object like
"identifiers": [
{
"IDENTIFIER": {
"primary": true
}
}
]
I used the following JSON code in config file,
"identifiers": {
"title": "Identifiers",
"type": "array",
"location": "body",
"items": {
"title": "Identifier Fields",
"type": "object",
"properties": {
"IDENTIFIER": {
"type": "object",
"properties": {
"primary": {
"title": "primary",
"required": true,
"type": "boolean",
"description": "",
"default": true
}
}
}
}
}
}
How to achieve this. Kindly help me.
Note : I can able to do using Object inside Object. but I don't want that.
Thanks in advance.

Empty sparse fieldset in JSON API

I have a resource (e.g. posts) which has a to-many relationship to other resources (e.g. comments). I do not need any fields of the related resource but their self-links (to fetch them asynchronously on demand). The response should look something like this:
{
"links": {
"self": "http://example.com/posts/1?xxx",
},
"data": [{
"type": "posts",
"id": "1",
"attributes": {
"title": "JSON API paints my bikeshed!"
},
"relationships": {
"comments": {
"links": {
"self": "http://example.com/posts/1/relationships/comments",
"related": "http://example.com/posts/1/comments"
},
"data": [
{ "type": "comments", "id": "5" },
{ "type": "comments", "id": "12" }
]
}
},
"links": {
"self": "http://example.com/posts/1"
}
}],
"included": [{
"type": "comments",
"id": "5",
"links": {
"self": "http://example.com/comments/5"
}
}, {
"type": "comments",
"id": "12",
"links": {
"self": "http://example.com/comments/12"
}
}]
}
My question is how should the URL for the request look like?
My idea would be to include the comments and then use an empty sparse fieldset to avoid getting any comment fields but just the self link (+id, type).
Hence, it should look something like http://example.com/posts/1?include=comments&fields[comments]=[].
So I need something like an empty sparse fieldset.
The JSON API specification does not say much about sparse fieldsets (http://jsonapi.org/format/#fetching-sparse-fieldsets) and their relation to links.
The JSON API was able to answer my question.
In short, the correct way to specify an empty sparse fieldset would be:
http://example.com/posts/1?include=comments&fields[comments]=
There's a discussion going on about whether to include the links to individual relationship items in the relationship object:
{
"links": {
"self": "http://example.com/posts/1",
},
"data": [{
"type": "posts",
"id": "1",
"attributes": {
"title": "JSON API paints my bikeshed!"
},
"relationships": {
"comments": {
"links": {
"self": "http://example.com/posts/1/relationships/comments",
"related": "http://example.com/posts/1/comments",
"item": [ "http://example.com/comments/5", "http://example.com/comments/12" ]
},
"data": [{
"type": "comments",
"id": "5",
"links": {
"about": "http://example.com/comments/5"
}
}, {
"type": "comments",
"id": "12",
"links": {
"about": "http://example.com/comments/12"
}
}]
}
},
"links": {
"self": "http://example.com/posts/1"
}
}]
}

Resources