Basic JSON syntax? - jsonlint

Here is part of
[
UserJSONImpl{
"id"=26136358,
"name"='BryanConnor',
"screenName"='thewhyaxis',
"location"='null',
"description"='TheWhyAxisisacollectionofindepthwritingaboutthevisualizationsthatdeserveyourattention.',
"isContributorsEnabled"=false,
I'm not too familiar with JSON syntax and I haven't found a source on the web that provides an introduction; when I try to parse each JSONObject in the JSONArray I get an error like
Expected a ',' or ']' at character 14
When I input into jsonlint:
Parse error on line 1:
[ UserJSONImpl{
-----^
Expecting 'STRING', 'NUMBER', 'NULL', 'TRUE', 'FALSE', '{', '[', ']'
What's wrong with my JSON?

[
{
"UserJSONImpl": {
"id": 26136358,
"name": "BryanConnor",
"screenName": "thewhyaxis",
"location": null,
"description": "TheWhyAxisisacollectionofindepthwritingaboutthevisualizationsthatdeserveyourattention.",
"isContributorsEnabled": false
}
}
]
Following http://json.org/
[ elements ] with elements as value,
value as object,
object as { members },
members as pair
pair as string : value
value as object
...

Related

Parse JSON Dictionary with Python3

I have a JSON representation that looks like the following:
{
"results": [
{
"vulnerabilities": [
],
}
]
}
I tried to output just the vulnerabilities portion, but the following doesnt work:
for key, value in json_object.items():
print(key, ' : ', value)
This prints out the whole results but not just the vulnerabilities
Assuming multiple dicts in results, each with a vulnerabilities key, you can do:
json_object = {
"results": [
{
"vulnerabilities": [
],
}
]
}
for result in json_object['results']:
for vuln in result['vulnerabilities']:
print(vuln)

"Athena.InvalidRequestException" in Step function

I'm trying to read the query string from input but step function gives - "Athena.InvalidRequestException"
{
"StartAt": "CallFunction",
"States": {
"CallFunction": {
"Type": "Task",
"Resource": "arn:aws:lambda:us-west-2:12345:function:readFile",
"ResultPath": "$.query",
"Next": "Start an Athena query"
},
"Start an Athena query": {
"Resource": "arn:aws:states:::athena:startQueryExecution.sync",
"Parameters": {
"QueryString": "$.query",
"WorkGroup": "primary",
"ResultConfiguration": {
"OutputLocation": "s3://test_athena/test1"
}
}
}
}
Intput of Start an Athena query state:
{
"Comment": "Insert your JSON here",
"query": "\"SELECT * FROM test1 LIMIT 10; \""
}
Getting the below error on Start an Athena query state :
{
"resourceType": "athena",
"resource": "startQueryExecution.sync",
"error": "Athena.InvalidRequestException",
"cause": "line 1:1: mismatched input '$'. Expecting: 'ALTER', 'ANALYZE', 'CALL', 'COMMIT', 'CREATE', 'DEALLOCATE', 'DELETE', 'DESC', 'DESCRIBE', 'DROP', 'EXECUTE', 'EXPLAIN', 'GRANT', 'INSERT', 'PREPARE', 'RESET', 'REVOKE', 'ROLLBACK', 'SET', 'SHOW', 'START', 'UNLOAD', 'UPDATE', 'USE', <query> (Service: AmazonAthena; Status Code: 400; Error Code: InvalidRequestException; Request ID: 2a99f6eb-b853-407f-b229-d309a4ca3f5c; Proxy: null)"
}
I'm new to AWS. Can someone help me out in this how to pass query object in QueryString parameter of Athena ?
You are missing the ".$" annotation in your QueryString key:
"QueryString.$": "$.query",
[...] The values of [your Parameter fields] can either be static values that you include in your state machine definition, or selected from either the input or the context object with a path. For key-value pairs where the value is selected using a path, the key name must end in .$.
Source: https://docs.aws.amazon.com/step-functions/latest/dg/input-output-inputpath-params.html#input-output-parameters
Also, you should add the following fields in your second state, to be explicit there:
"Type": "Task",
"End": true

Assert count in nested json

I have following Katalon code to make sure the count response from API is correct
but I am getting an error so I need help to see what is missing in my code.
No signature of method: Script1568233794882.assertThat() is applicable for argument types: (java.lang.Integer) values: [29]
response text:
{
"Error": {
"A": {
"dependency": [
],
"duplicateRows": [
],
"requiredFieldRows": [
]
}
},
"Good": {
"A": {
"count": 29
},
"B": {
"count": 35
},
"C": {
"count": 37
}
},
"type": "Test"
}
I have tried this
def response = WS.sendRequest(requestObject)
def responseList = new JsonSlurper().parseText(response.getResponseText())
println('response text: \n' + JsonOutput.prettyPrint(JsonOutput.toJson(responseList)))
assertThat(responseList.Good.A.count).isEqualTo("29")
Also tried using [0], but it is also not working with error java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer
assertThat(responseList.Good[0].A).isEqualTo("29")
Try using the plain Groovy assert. Change your assertion line to the following:
assert responseList.Good.A.count == 29

Inserting JSON schema into U-SQL table

I want to insert JSON schema for my U-SQL table in DataLake Analysts tool. Here is my JSON schema
DECLARE #json string= "{
"definitions": {},
"$schema": "http://json-schema.org/draft-06/schema#",
"$id": "http://getIQOS.com/IQOSAbandonedCartV1.json",
"title": "CE:I:ORD:ABC",
"type": "object",
"properties": {
"altriaOrchestrated": {
"$id": "/properties/altriaOrchestrated",
"type": "integer",
"title": "Altria Orchestrated",
"description": "Specifies whether the AT object is being called by Core Services (1) or from an outside source (0)",
"default": 0,
"enum": [
0, 1
],
"examples": [
0, 1
],
"minimum": 0,
"maximum": 1
},
"required": [
"altriaOrchestrated",
"initiativeName",
"date",
"inventory"
]
}"
I am getting below error and can not understand what error it is. I my development halted because of this issue.
AGG ALL AND ARRAY BETWEEN BIGINT BIT BINARY BY COLUMNSET CREATED CSHARP CURRENT DATETIME DATETIME2 DECIMAL EXISTS FILE FLOAT FOLLOWING GROUP IN INT IS LENGTH LCID MAP MAX MODIFIED MONEY NULL NVARCHAR OR OVER PARTITION PRECEDING REAL SMALLINT SQL STRUCT TINYINT UNBOUNDED UNIQUEIDENTIFIER VARBINARY VARCHAR WITHIN string-literal numeric-literal character-literal punctuation-mark identifier quoted-identifier reserved-identifier variable system-variable '[' ']' '(' '{' '}' '=' '.' '*' ':' '?' '<' '>'
Per my testing, you could leverage the double quote, backslash as follows to declare your json string parameter.
DECLARE #json string ="{"+
"\"definitions\": {},"+
"\"$schema\": \"http://json-schema.org/draft-06/schema#\","+
"\"$id\": \"http://getIQOS.com/IQOSAbandonedCartV1.json\","+
"\"title\": \"CE:I:ORD:ABC\","+
"\"type\": \"object\","+
"\"properties\": {"+
"\"altriaOrchestrated\": {}"+
"}"+
"}";
Also, you could leverage Verbatim C# string literals that simplify the handling of such characters by prepending the # character in front of the starting double quote of the string. For your json string, you could declare it as follows:
DECLARE #json string =#"{
""definitions"": {},
""$schema"": ""http://json-schema.org/draft-06/schema#"",
""$id"": ""http://getIQOS.com/IQOSAbandonedCartV1.json"",
""title"": ""CE:I:ORD:ABC"",
""type"": ""object"",
""properties"": {
""altriaOrchestrated"": {}
}
}";
Note:
The maximal size of a column of type string is 128kB in U-SQL (based on the byte count of the string value represented in UTF-8 encoding).
Details you could follow Textual Types and Literals.

invalid argument type in call to function 'ATTRIBUTES()' in ArangoDB

I have stored my Data in the give formate in AreangoDB, My collection name in DSP:
"data": {
"1": [ {"db_name": "DSP"}, {"rel": "2"} ],
"2": [ {"rel_name": "DataSource"}, {"tuple": "201"}, {"tuple": "202"}, {"tuple": "203"} ],
"201": [ {"src_id": "Pos201510070"}, {"src_name": "Postgres"}, {"password": "root"}, {"host": "localhost"}, {"created_date": "20151007"}, {"user_name": "postgres"}, {"src_type": "Structured"}, {"db_name": "postgres"}, {"port": "None"} ],
"202": [ {"src_id": "pos201510060"}, {"src_name": "Postgres"},{"password": "root"}, {"host": "localhost"}, {"created_date": "20151006"}, {"user_name": "postgres"}, {"src_type": "Structured"}, {"db_name": "DSP"}, {"port": "5432"} ],
"203": [ {"src_id": "pos201510060"}, {"src_name": "Postgres"}, {"password": "root"}, {"host": "localhost"}, {"created_date": "20151006"}, {"user_name": "postgres"},{"src_type": "Structured"},{"db_name": "maindb"},{"port": "5432"} ]
}
I am executing a query with the above data in the following format:
FOR p IN NestedDSP
LET attributes = ATTRIBUTES(p)
FOR attribute IN attributes
LET key = ATTRIBUTES(attribute)[0]
LET value = attribute[key]
RETURN { subject: attribute, predicate: key, object: value }
When I submit my query to ArangoDB, it returns the response as:
Warnings:
[1542], 'invalid argument type in call to function 'ATTRIBUTES()''
[1542], 'invalid argument type in call to function 'ATTRIBUTES()''
[1542], 'invalid argument type in call to function 'ATTRIBUTES()''
[1542], 'invalid argument type in call to function 'ATTRIBUTES()''
Result:
[
{
"subject": "data",
"predicate": null,
"object": null
},
{
"subject": "_id",
"predicate": null,
"object": null
},
{
"subject": "_rev",
"predicate": null,
"object": null
},
{
"subject": "_key",
"predicate": null,
"object": null
}
]
Please tell me what is the problem with this query, and why the answer is like the above..I am working in ArangoDB-2.7.3-win64.
Thanks
Let me demonstrate how to construct such a complex query digging deep into nested data structures. I start out taking the outer parts of the query, to have an inner result:
FOR p IN NestedDSP
LET attributes = ATTRIBUTES(p)
FOR attribute IN attributes
RETURN attribute
which gives me:
[
"data",
"_rev",
"_key",
"_id"
]
So lets dive deeper into the next layer. I guess you're only interested in the values present underneath data key right? so we pick p.data:
FOR p IN NestedDSP
LET attributes = ATTRIBUTES(p.data)
FOR attribute IN attributes
RETURN attribute
which then gives me the keys for your next inner array:
[
"203",
"202",
"201",
"2",
"1"
]
We now explore what we find attached to these nodes:
FOR p IN NestedDSP
LET attributes = ATTRIBUTES(p.data)
FOR oneAttribute IN attributes
LET keys = p.data[oneAttribute]
RETURN keys
Its Again an array, which we need to iterate into using a FOR loop over keys:
[
[
{
"src_id" : "pos201510060"
},
{
"src_name" : "Postgres"
}, ...
We add this additional FOR-loop:
FOR p IN NestedDSP
LET attributes = ATTRIBUTES(p.data)
FOR oneAttribute IN attributes
LET keys = p.data[oneAttribute]
FOR key IN keys
RETURN key
we get the inner most objects:
[
{
"src_id" : "pos201510060"
},
{
"src_name" : "Postgres"
},
{
"password" : "root"
},
...
You wanted to use the ATTRIBUTES function, but the objects only have one member, so we can access [0]:
FOR p IN NestedDSP
LET attributes = ATTRIBUTES(p.data)
FOR oneAttribute IN attributes
LET keys = p.data[oneAttribute]
FOR key IN keys
LET keyAttributes=ATTRIBUTES(key)
RETURN keyAttributes
Which gives us the object keys, one per inner most object:
[
[
"src_id"
],
[
"src_name"
],
We inspect whether we now get only the object keys of the inner most structure; we pick the variable names a little more clever than above:
FOR p IN NestedDSP
LET attributes = ATTRIBUTES(p.data)
FOR oneAttribute IN attributes
LET pairs = p.data[oneAttribute]
FOR onePair IN pairs
LET pairKey=ATTRIBUTES(onePair)[0]
RETURN pairKey
YES:
[
"src_id",
"src_name",
"password",
"host",
...
So now its time to construct the results object as you wanted them:
FOR p IN NestedDSP
LET attributes = ATTRIBUTES(p.data)
FOR oneAttribute IN attributes
LET pairs = p.data[oneAttribute]
FOR onePair IN pairs
LET pairKey=ATTRIBUTES(onePair)[0]
RETURN { subject: oneAttribute, predicate: pairKey, object: onePair[pairKey] }
The subject is the number identifying the outermost item, the predicate is the object key, and the object is the value in it:
[
{
"subject" : "203",
"predicate" : "src_id",
"object" : "pos201510060"
},
{
"subject" : "203",
"predicate" : "src_name",
"object" : "Postgres"
}
Which is hopefully what you wanted?

Resources