I have a list of a custom object. Each object has the following structure:
"id": "id_1",
"parent_id": "id_0",
"class": "class0",
"label": "label",
"order": "order",
"text": "text",
"children"[
"id": "id_1_1",
"parent_id": "id_1",
"class": "class0",
"label": "label",
"text": "text"
"children"[]
....
...
...
]
I want to obtain from this input list a JSON output like this:
Related
I have a simple JSON schema that's used to define a tree of objects that are labeled with an Object Identifier. These objects are recursive and look identical, so the JSON schema just uses a "$ref": "#".
What I would like to do is validate that the actual numeric OID structure is constructed correctly. Right now I'm validating that it starts with the right prefix (1.2.3), but if the subsequent structure is screwed up (e.g. the parent is 1.2.3.6 but someone adds children of 1.2.3.6.1 and 1.2.3.2.2) it won't be caught.
I'm not sure how I can reference the oid field in the parent object to check against the child. Can someone point me in the right direction?
My schema:
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://my-site/my-schema.json",
"title": "My JSON Schema",
"description": "A fancy JSON schema for a tree of objects",
"type": "object",
"properties": {
"oid": {
"description": "The OID",
"type": "string",
"pattern": "^1.2.3"
},
"description": {
"description": "A description",
"type": "string"
},
"children": {
"description": "Children",
"type": [
"array",
"null"
],
"items": {
"$ref": "#"
}
}
},
"required": [
"oid",
"description",
"children"
]
}
Example data:
{
"oid": "1.2.3",
"description": "Parent",
"children": [
{
"oid": "1.2.3.1",
"description": "Group 1",
"children": [
{
"oid": "1.2.3.1.1",
"description": "Group 1.1",
"children": [
{
"oid": "1.2.3.1.1.1",
"description": "Item 1.1.1",
"children": null
}
]
},
{
"oid": "1.2.3.1.2",
"description": "Group 1.2",
"children": [
{
"oid": "1.2.3.1.2.1",
"description": "Item 1.2.1",
"children": null
},
{
"oid": "1.2.3.1.2.2",
"description": "Item 1.2.2",
"children": null
}
]
}
]
}
]
}
I have a JSON data and able to get the JSON data into a string.
I wish to get a json array from the root object one by one (using a loop if many are there)
The returned object must be of type "com.google.gson.JsonObject" as another method takes this object as input to get me the attribute values.
my json looks like this:
I would be needing the json array in "Resources" -
{
"totalResults": 2,
"startIndex": 1,
"schemas": [
"urn:ietf:params:scim:api:messages:2.0:ListResponse"
],
"Resources": [
{
"owner": {},
"application": {
"displayName": "Non Auth App",
"value": "4028b88168fa3d38016900d1759405a6",
"$ref": "http://localhost:8080/identityiq/scim/v2/Applications/4028b88168fa3d38016900d1759405a6"
},
"meta": {
"created": "2019-03-22T18:40:30.505+05:30",
"location": "http://localhost:8080/identityiq/scim/v2/Entitlements/297eff8a699f8b3a0169a5863769008b",
"version": "W/\"1553260230505\"",
"resourceType": "Entitlement"
},
"schemas": [
"urn:ietf:params:scim:schemas:sailpoint:1.0:Entitlement"
],
"displayableName": "reader",
"aggregated": false,
"id": "297eff8a699f8b3a0169a5863769008b",
"requestable": true,
"attribute": "Privileges",
"type": "Entitlement",
"descriptions": [],
"value": "reader"
},
{
"owner": {},
"application": {
"displayName": "Non Auth App",
"value": "4028b88168fa3d38016900d1759405a6",
"$ref": "http://localhost:8080/identityiq/scim/v2/Applications/4028b88168fa3d38016900d1759405a6"
},
"meta": {
"created": "2019-03-18T19:11:47.912+05:30",
"location": "http://localhost:8080/identityiq/scim/v2/Entitlements/297eff8a6990fc49016991096d08001e",
"version": "W/\"1552916507912\"",
"resourceType": "Entitlement"
},
"schemas": [
"urn:ietf:params:scim:schemas:sailpoint:1.0:Entitlement"
],
"displayableName": "admin",
"aggregated": false,
"id": "297eff8a6990fc49016991096d08001e",
"requestable": true,
"attribute": "Privileges",
"type": "Entitlement",
"descriptions": [],
"value": "admin"
}
]
}
Any help is appreciated.
I have the following db:
{
"a": [{
"name": "foo",
"thing": [{
"name": "bar",
"lyrics": ["1", "2", "3"]
}]
}, {
"name": "abc",
"thing": [{
"name": "123",
"list": ["one", "two"]
}]
}]
}
I can't seem to query it correctly. These two queries return the same thing, the entire db:
db.test.find({"a.name":"abc"})
db.test.find({"a.name":"foo"})
How do I find one collection instead of the whole db?
I would expect the first query to return:
{
"name": "abc",
"thing": [{
"name": "123",
"list": ["one", "two"]
}]
}
The two queries return the same document, because both queries match it.
This is one document
[{
"a": [{
"name": "foo",
"thing": [{
"name": "bar",
"lyrics": ["1", "2", "3"]
}]
}, {
"name": "abc",
"thing": [{
"name": "123",
"list": ["one", "two"]
}]
}]
}]
This is two documents
[{
"a": [{
"name": "foo",
"thing": [{
"name": "bar",
"lyrics": ["1", "2", "3"]
}]
}]
},
{
"a": [{
"name": "abc",
"thing": [{
"name": "123",
"list": ["one", "two"]
}]
}]
}]
You can get stats on of a collection like so
db.test.stats()
"count" will tell you how many documents are there.
Edit: To add to this, in your collection "test" a document has 1 field, which is "a" and is of type array that holds objects (documents). It has 2 array elements
First
{
"name": "foo",
"thing": [{
"name": "bar",
"lyrics": ["1", "2", "3"]
}]
}
Second
{
"name": "abc",
"thing": [{
"name": "123",
"list": ["one", "two"]
}]
}
Everything inside curly braces {..}, including the braces themselves, is a one single document, i.e. the whole your database contains only one document that you receive for any matching query. To receive the desired result, you have to re-write your JSON document as an array of documents inside square braces [..].
I would like to create a variable for a list of select options that can be re-used for multiple settings. example (variable state_list in the code below)...
{
"name": "Shop page",
"settings": [
{
"type": "header",
"content": "State"
},
{
"type": "select",
"id": "state_select",
"label": "Choose State...",
"options": state_list,
"default": "Alabama",
"info": "info text here"
}
]
}
and then (obviously) somewhere else, define that list. something like this...
var state_list = [
{
"group": "states",
"value": "AL",
"label": "Alabama"
},
{
"group": "states",
"value": "AK",
"label": "Alaska"
},
{
"group": "states",
"value": "AZ",
"label": "Arizona"
}
etc.
]
please - someone tell me this is possible!
You can't use variables in the schema object.
The schema objects accepts only JSON syntax and you can't pass any liquid variables in it.
This applies for the settings_schema.json file and the {% schema %} section.
You can't pass any liquid object, translatable strings or anything other piece of data that is not static text (a.k.a JSON object).
So if you are trying to do the following, it's INVALID:
{
"type": "select",
"id": "select",
"label": "Select",
"options": [
{{ select_options }}
],
"default": "option"
}
I want to index & search nested json in solr. Here is my json code
{
"id": "44444",
"headline": "testing US",
"generaltags": [
{
"type": "person",
"name": "Jayalalitha",
"relevance": "0.334",
"count": 1
},
{
"type": "person",
"name": "Kumar",
"relevance": "0.234",
"count": 1
}
],
"socialtags": {
"type": "SocialTag",
"name": "US",
"importance": 2
},
"topic": {
"type": "Topic",
"name": "US",
"score": "0.936"
}
}
When I try to Index, I'm getting the error "Error parsing JSON field value. Unexpected OBJECT_START"
When we tried to use Multivalued Field & index, we couldn't able to search using the multivalued field? Its returning "Undefined Field"
Also Please advice if I need to do any changes in schema.xml file?
You are nesting child documents within your document. You need to use the proper syntax for nested child documents in JSON:
[
{
"id": "1",
"title": "Solr adds block join support",
"content_type": "parentDocument",
"_childDocuments_": [
{
"id": "2",
"comments": "SolrCloud supports it too!"
}
]
},
{
"id": "3",
"title": "Lucene and Solr 4.5 is out",
"content_type": "parentDocument",
"_childDocuments_": [
{
"id": "4",
"comments": "Lots of new features"
}
]
}
]
Have a look at this article which describes JSON child documents and block joins.
Using the format mentioned by #qux you will face "Expected: OBJECT_START but got ARRAY_START at [16]",
"code": 400
as when JSON starting with [....] will parsed as a JSON array
{
"id": "44444",
"headline": "testing US",
"generaltags": [
{
"type": "person",
"name": "Jayalalitha",
"relevance": "0.334",
"count": 1
},
{
"type": "person",
"name": "Kumar",
"relevance": "0.234",
"count": 1
}
],
"socialtags": {
"type": "SocialTag",
"name": "US",
"importance": 2
},
"topic": {
"type": "Topic",
"name": "US",
"score": "0.936"
}
}
The above format is correct.
Regarding searching. Kindly use the index to search for the elements of the JSON array.
The workaround for this can be keeping the whole JSON object inside other JSON object and the indexing it
I was suggesting to keep the whole data inside another JSON object. You can try the following way
{
"data": [
{
"id": "44444",
"headline": "testing US",
"generaltags": [
{
"type": "person",
"name": "Jayalalitha",
"relevance": "0.334",
"count": 1
},
{
"type": "person",
"name": "Kumar",
"relevance": "0.234",
"count": 1
}
],
"socialtags": {
"type": "SocialTag",
"name": "US",
"importance": 2
},
"topic": {
"type": "Topic",
"name": "US",
"score": "0.936"
}
}
]
}
see the syntax in http://yonik.com/solr-nested-objects/
$ curl http://localhost:8983/solr/demo/update?commitWithin=3000 -d '
[
{id : book1, type_s:book, title_t : "The Way of Kings", author_s : "Brandon Sanderson",
cat_s:fantasy, pubyear_i:2010, publisher_s:Tor,
_childDocuments_ : [
{ id: book1_c1, type_s:review, review_dt:"2015-01-03T14:30:00Z",
stars_i:5, author_s:yonik,
comment_t:"A great start to what looks like an epic series!"
}
,
{ id: book1_c2, type_s:review, review_dt:"2014-03-15T12:00:00Z",
stars_i:3, author_s:dan,
comment_t:"This book was too long."
}
]
}
]'
supported from solr 5.3