why this error
xhr: [object XMLHttpRequest]
textStatus: parsererror
errorThrown: Invalid JSON: [ { "id": "10000000", "label": "10000000" }, { "id": "10000001", "label": "10000001" }, { "id": "10000003", "label": "10000003" }, { "id": "10000005", "label": "10000005" }, { "id": "10000006", "label": "10000006" } ]
Copied and pasted this:
[ { "id": "10000000", "label": "10000000" }, { "id": "10000001", "label": "10000001" }, { "id": "10000003", "label": "10000003" }, { "id": "10000005", "label": "10000005" }, { "id": "10000006", "label": "10000006" }]
to JSONlint and it says it's valid.
Can you post the original JSON if that is the original then the it is missing a root key
var textStatus = {"keys":[{"id":"...", "label":"..."},{"id":"...","label":"..."}]}
Also the whole thing needs to be inside {} to make it an object what you had is just an array
Related
I have the following output coming from a step function task: ListObjectsV2
{
"Contents": [
{
"ETag": "\"86c12c034bc6c30cb89b500b954c188f\"",
"Key": "55271f52fffe4461a2ee3228ebb97157/input/batch_1.csv",
"LastModified": "2023-02-09T13:46:20Z",
"Size": 796014,
"StorageClass": "STANDARD"
},
{
"ETag": "\"58e4a770e0f66073b00d185df500f07f\"",
"Key": "55271f52fffe4461a2ee3228ebb97157/input/batch_2.csv",
"LastModified": "2023-02-09T13:47:20Z",
"Size": 934038,
"StorageClass": "STANDARD"
},
{
"ETag": "\"460abd0de64d5cb67e8f0d46878cb1ef\"",
"Key": "55271f52fffe4461a2ee3228ebb97157/input/batch_3.csv",
"LastModified": "2023-02-09T13:46:57Z",
"Size": 794264,
"StorageClass": "STANDARD"
},
{
"ETag": "\"1bfedc3dc92e4ba8d04e24b9b5a0ed58\"",
"Key": "55271f52fffe4461a2ee3228ebb97157/input/batch_4.csv",
"LastModified": "2023-02-09T13:46:24Z",
"Size": 788756,
"StorageClass": "STANDARD"
},
{
"ETag": "\"9d6c434ce5ebdf203a790fbcf19338dc\"",
"Key": "55271f52fffe4461a2ee3228ebb97157/input/batch_5.csv",
"LastModified": "2023-02-09T13:47:07Z",
"Size": 831156,
"StorageClass": "STANDARD"
}
],
"IsTruncated": false,
"KeyCount": 5,
"MaxKeys": 1000,
"Name": "vita-internal-text-classification-dev-183576513728",
"Prefix": "55271f52fffe4461a2ee3228ebb97157"
}
I want to have an array containing only the Key key, to pass to the next state, like so:
[
{
"Key": "55271f52fffe4461a2ee3228ebb97157/input/batch_1.csv",
},
{
"Key": "55271f52fffe4461a2ee3228ebb97157/input/batch_2.csv",
},
{
"Key": "55271f52fffe4461a2ee3228ebb97157/input/batch_3.csv",
},
{
"Key": "55271f52fffe4461a2ee3228ebb97157/input/batch_4.csv",
},
{
"Key": "55271f52fffe4461a2ee3228ebb97157/input/batch_5.csv",
}
]
So far I've tried setting the ResultPath to:
$.Contents[*].Key
$.Contents[*].['Key']
What I get is:
[
"55271f52fffe4461a2ee3228ebb97157/input/batch_1.csv",
"55271f52fffe4461a2ee3228ebb97157/input/batch_2.csv",
"55271f52fffe4461a2ee3228ebb97157/input/batch_3.csv",
"55271f52fffe4461a2ee3228ebb97157/input/batch_4.csv",
"55271f52fffe4461a2ee3228ebb97157/input/batch_5.csv",
]
But I've gotten bad output from that, any help?
The way I've solved this is to use an Inline Map state with a Pass state to build the necessary format. You can see this pattern in an example here for how to use Step Functions Distributed Map to bulk delete objects from S3. You can see this in the inner Create Object Identifier Array Map state. If you were doing this in Standard Workflows, this could be a cost concern given the number of state transitions involved. But since in the Item Processor I'm using Express Workflows, which are billed by duration (and these are super fast), it works pretty well.
{
"Comment": "A state machine to bulk delete objects from S3 using Distributed Map",
"StartAt": "Confirm Bucket Provided",
"States": {
"Confirm Bucket Provided": {
"Type": "Choice",
"Choices": [
{
"Not": {
"Variable": "$.bucket",
"IsPresent": true
},
"Next": "Fail - No Bucket"
}
],
"Default": "Check for Prefix"
},
"Check for Prefix": {
"Type": "Choice",
"Choices": [
{
"Not": {
"Variable": "$.prefix",
"IsPresent": true
},
"Next": "Generate Parameters - Without Prefix"
}
],
"Default": "Generate Parameters - With Prefix"
},
"Generate Parameters - Without Prefix": {
"Type": "Pass",
"Parameters": {
"Bucket.$": "$.bucket",
"Prefix": ""
},
"ResultPath": "$.list_parameters",
"Next": "Delete Objects from S3 Bucket"
},
"Fail - No Bucket": {
"Type": "Fail",
"Error": "InsuffcientArguments",
"Cause": "No Bucket was provided"
},
"Generate Parameters - With Prefix": {
"Type": "Pass",
"Next": "Delete Objects from S3 Bucket",
"Parameters": {
"Bucket.$": "$.bucket",
"Prefix.$": "$.prefix"
},
"ResultPath": "$.list_parameters"
},
"Delete Objects from S3 Bucket": {
"Type": "Map",
"ItemProcessor": {
"ProcessorConfig": {
"Mode": "DISTRIBUTED",
"ExecutionType": "EXPRESS"
},
"StartAt": "Create Object Identifier Array",
"States": {
"Create Object Identifier Array": {
"Type": "Map",
"ItemProcessor": {
"ProcessorConfig": {
"Mode": "INLINE"
},
"StartAt": "Create Object Identifier",
"States": {
"Create Object Identifier": {
"Type": "Pass",
"End": true,
"Parameters": {
"Key.$": "$.Key"
}
}
}
},
"ItemsPath": "$.Items",
"ResultPath": "$.object_identifiers",
"Next": "Delete Objects"
},
"Delete Objects": {
"Type": "Task",
"Next": "Clear Output",
"Parameters": {
"Bucket.$": "$.BatchInput.bucket",
"Delete": {
"Objects.$": "$.object_identifiers"
}
},
"Resource": "arn:aws:states:::aws-sdk:s3:deleteObjects",
"Retry": [
{
"ErrorEquals": [
"States.ALL"
],
"BackoffRate": 2,
"IntervalSeconds": 1,
"MaxAttempts": 6
}
],
"ResultSelector": {
"Deleted.$": "$.Deleted",
"RetryCount.$": "$$.State.RetryCount"
}
},
"Clear Output": {
"Type": "Pass",
"End": true,
"Result": {}
}
}
},
"ItemReader": {
"Resource": "arn:aws:states:::s3:listObjectsV2",
"Parameters": {
"Bucket.$": "$.list_parameters.Bucket",
"Prefix.$": "$.list_parameters.Prefix"
}
},
"MaxConcurrency": 5,
"Label": "S3objectkeys",
"ItemBatcher": {
"MaxInputBytesPerBatch": 204800,
"MaxItemsPerBatch": 1000,
"BatchInput": {
"bucket.$": "$.list_parameters.Bucket"
}
},
"ResultSelector": {},
"End": true
}
}
}
I need to standardize the object response key/values so that they are easier to parse/traverse using the tool I'm integrating.
Starting with the following JSON:
{
"status": true,
"body": {
"phone": "+1 937-830-1167",
"address": "2323 kuhku",
"linkedin": "uhku",
"twitter": "uhukh",
"education": "weeww",
"work_experience": "wewaew",
"write_something_about_you": "yugtyt",
"why_you_think_you_are_good_for_this_job": "kuhhuk",
"write_your_assignment_question": "kuhghuhghj",
"upload_your_attachment": null,
"upload_your_resume_here": null
}
}
Using Dart, what would be the best way to reformat as shown?
{
"status": true,
"body": {
"answers":[
{
"label": "phone",
"answer":"+1 937-830-1167"
},
{
"label": "address",
"answer":"2323 kuhku"
},
{
"label": "linkedin",
"answer": "uhku"
},
{
"label": "twitter",
"answer": "uhku"
},
{
"label": "education",
"answer": "uhku"
},
{
"label": "work_experience",
"answer": "uhku"
},
{
"label": "write_something_about_you",
"answer": "uhku"
},
{
"label": "why_you_think_you_are_good_for_this_job",
"answer": "uhku"
},
{
"label": "write_your_assignment_question",
"answer": "uhku"
},
{
"label": "upload_your_attachment",
"answer": "uhku"
},
{
"label": "write_something_about_you",
"answer": "upload_your_resume_here"
}
]
}
}
I'm somewhat limited by the tool I'm using so this will make it much easier to parse the JSON object with JSON Path as needed.
Looks like something that should be easily doable as:
var json = ... your json ...;
var result = {
"status": json["status"],
"body": [for (var e in json["body"].entries)
{"label": e.key, "answer": e.value}
]
};
Create a new JSON object with the same "status" and a "body" which is a list instead of a map, and for each entry in the original map, create a JSON object with a "label" and "answer" taken from the key and value of the map entry.
I am trying to dynamically render a spec (Specification) of a collection from an RPC. Can't get it to work. Here I have attached the code of both 'module->mappable parameters' and the 'remote procedure->communication' here.
module -> mappable parameters
[
{
"name": "birdId",
"type": "select",
"label": "Bird Name",
"required": true,
"options": {
"store": "rpc://selectbird",
"nested": [
{
"name": "variables",
"type": "collection",
"label": "Bird Variables",
"spec": [
"rpc://birdVariables"
]
}
]
}
}
]
remote procedure -> communication
{
"url": "/bird/get-variables",
"method": "POST",
"body": {
"birdId": "{{parameters.birdId}}"
},
"headers": {
"Authorization": "Apikey {{connection.apikey}}"
},
"response": {
"iterate":{
"container": "{{body.data}}"
},
"output": {
"name": "{{item.name}}",
"label": "{{item.label}}",
"type": "{{item.type}}"
}
}
}
Thanks in advance.
Just tried the following and it worked. According to Integromat's Docs you can use the wrapper directive for the rpc like so:
{
"url": "/bird/get-variables",
"method": "POST",
"body": {
"birdId": "{{parameters.birdId}}"
},
"headers": {
"Authorization": "Apikey {{connection.apikey}}"
},
"response": {
"iterate":"{{body.data}}",
"output": {
"name": "{{item.name}}",
"label": "{{item.label}}",
"type": "{{item.type}}"
},
"wrapper": [{
"name": "variables",
"type": "collection",
"label": "Bird Variables",
"spec": "{{output}}"
}]
}
}
Your mappable parameters would then look like:
[
{
"name": "birdId",
"type": "select",
"label": "Bird Name",
"required": true,
"options": {
"store": "rpc://selectbird",
"nested": "rpc://birdVariables"
}
}
]
Needing this myself. Pulling in custom fields that have different types but would like them all to show for the user to update customs fields or when creating a contact be able to update them. Not sure if best to have them all show or have a select drop down then let the user use the map for more than one.
Here is my response from a Get for custom fields. Could you show how my code should look. Got little confused as usualy look for add a value in the output and do you need two separate RPC's in integromat? Noticed your store and nested were different.
{
"customFields": [
{
"id": "5sCdYXDx5QBau2m2BxXC",
"name": "Your Experience",
"fieldKey": "contact.your_experience",
"dataType": "LARGE_TEXT",
"position": 0
},
{
"id": "RdrFtK2hIzJLmuwgBtAr",
"name": "Assisted by",
"fieldKey": "contact.assisted_by",
"dataType": "MULTIPLE_OPTIONS",
"position": 0,
"picklistOptions": [
"Tom",
"Jill",
"Rick"
]
},
{
"id": "uyjmfZwo0PCDJKg2uqrt",
"name": "Is contacted",
"fieldKey": "contact.is_contacted",
"dataType": "CHECKBOX",
"position": 0,
"picklistOptions": [
"I would like to be contacted"
]
}
]
}
I have a problem to find out only a determined value in a json using jsonpath.
I have this json:
{"tvs": {
{ "tv": [
{
"serial": "HD1300",
"data": [
{
"title": "manufacturer",
"value": "lg"
},
{
"title": "color",
"value": "silver"
},
{
"title": "inches",
"value": 32
},
{
"title": "connection",
"value": 220
},
{
"title": "connection",
"value": 400
}
]
}.. more tvs
And I want to know if the value connection:400 is present for serial hd1300
I already tried with:
$.tvs.[?(#.serial=='hd1340')].data.[?(#.title== 'connection'),(#.value==400)]
But my problem is that I retrieve also the "connection" with 200. How can I filter to get only this value?
I think you might have an error in your JSON (extra brace between tvs and tv). I was able to get this to work on http://jsonpath.com.
{"tvs":
{ "tv": [
{
"serial": "HD1300",
"data": [
{
"title": "manufacturer",
"value": "lg"
},
{
"title": "color",
"value": "silver"
},
{
"title": "inches",
"value": 32
},
{
"title": "connection",
"value": 220
},
{
"title": "connection",
"value": 400
}
]}
]}
}
$.tvs.tv.[?(#.serial=='HD1300')].data.[?(#.title=='connection' && #.value=='400')]
I'm having a bit of trouble doing something with JSONPath. This is what I have:
[
{
"id": {
"type": "literal",
"value": "123456789",
"datatype": "http://www.w3.org/2001/XMLSchema#string"
},
"name": {
"type": "literal",
"value": "John Doe",
"datatype": "http://www.w3.org/2001/XMLSchema#string"
}
},
{
"id": {
"type": "literal",
"value": "2123456789",
"datatype": "http://www.w3.org/2001/XMLSchema#string"
},
"name": {
"type": "literal",
"value": "Jane Doe",
"datatype": "http://www.w3.org/2001/XMLSchema#string"
}
}
]
}
]
And what I would like to get after applying a pattern is:
[
{
"id": "123456789",
"name": "John Doe"
},
{
"id": "2123456789",
"name": "Jane Doe"
}
]
Is this possible? The best I am doing is ["123456789", "John Doe","2123456789","Jane Doe"]
How should the pattern look like?
With DefiantJS (http://defianjs.com), you can query JSON structure using XPath expressions. DefiantJS extends the global object JSON with the method "search" and it returns matches as an array-like object.
Here is an example code;
var data = [
{
"id": {
"type": "literal",
"value": "123456789",
"datatype": "http://www.w3.org/2001/XMLSchema#string"
},
"name": {
"type": "literal",
"value": "John Doe",
"datatype": "http://www.w3.org/2001/XMLSchema#string"
}
},
{
"id": {
"type": "literal",
"value": "2123456789",
"datatype": "http://www.w3.org/2001/XMLSchema#string"
},
"name": {
"type": "literal",
"value": "Jane Doe",
"datatype": "http://www.w3.org/2001/XMLSchema#string"
}
}
],
found = JSON.search(data, '//value'),
str = '';
for (var i=0; i<found.length; i++) {
str += found[i] +'<br/>';
}
document.getElementById('output').innerHTML = str;
To see this code in action, check out this fiddle; http://jsfiddle.net/hbi99/4BZMm/
For more useful XPath expressions, see the like XPath Evaluator here; http://defiantjs.com/#xpath_evaluator