Converting a json looking simple value string to a ColdFusion structure - coldfusion

I do the following in ColdFusion script:
svc = new http();
svc.setMethod('post');
svc.setCharset('utf-8');
svc.setUrl('https://api.stripe.com/v1/charges');
svc.addParam(type='header', name='Authorization', value='Bearer #Stripe.mySecretKey#');
svc.addParam(type='formfield', name='amount', value=form.amount);
svc.addParam(type='formfield', name='currency', value='usd');
svc.addParam(type='formfield', name='card', value='#form.card#');
svc.addParam(type='formfield', name='description', value='#form.email#');
prefix = svc.send().getPrefix();
response = prefix.FileContent;
WriteOutput(response & '<br>');
WriteOutput(IsSimpleValue(response) & '<br>');
WriteOutput(IsJSON(response));
dump(response);
And I'm getting a string that looks like this:
{ "id": "ch_6HAwRK92OsQPoA", "object": "charge", "created": 1432149035, "livemode": false, "paid": true, "status": "paid", "amount": 100, "currency": "usd", "refunded": false, "source": { "id": "card_6HAwNGtbdzFdq0", "object": "card", "last4": "4242", "brand": "Visa", "funding": "credit", "exp_month": 12, "exp_year": 2015, "fingerprint": "I2nSF7gS79j9Zhei", "country": "US", "name": null, "address_line1": null, "address_line2": null, "address_city": null, "address_state": null, "address_zip": null, "address_country": null, "cvc_check": "pass", "address_line1_check": null, "address_zip_check": null, "dynamic_last4": null, "metadata": {}, "customer": null }, "captured": true, "card": { "id": "card_6HAwNGtbdzFdq0", "object": "card", "last4": "4242", "brand": "Visa", "funding": "credit", "exp_month": 12, "exp_year": 2015, "fingerprint": "I2nSF7gS79j9Zhei", "country": "US", "name": null, "address_line1": null, "address_line2": null, "address_city": null, "address_state": null, "address_zip": null, "address_country": null, "cvc_check": "pass", "address_line1_check": null, "address_zip_check": null, "dynamic_last4": null, "metadata": {}, "customer": null }, "balance_transaction": "txn_6HAw4bAUUZ6trA", "failure_message": null, "failure_code": null, "amount_refunded": 0, "customer": null, "invoice": null, "description": "PhillipSenn#gmail.com", "dispute": null, "metadata": {}, "statement_descriptor": null, "fraud_details": {}, "receipt_email": null, "receipt_number": null, "shipping": null, "destination": null, "application_fee": null, "refunds": { "object": "list", "total_count": 0, "has_more": false, "url": "/v1/charges/ch_6HAwRK92OsQPoA/refunds", "data": [] } }
As well as "YES" and "YES".
If I do a DeserializeJSON(response), then I get a 500 error.
So, how do I put this simple value string, which looks like json, in a ColdFusion structure so that I can reference response.id and response.paid?

Something's wrong in your CF or web server setup.
I tested your json with CF11 on tryCF and it works.
<cfscript>
json = '{ "id": "ch_6HAwRK92OsQPoA", "object": "charge", "created": 1432149035, "livemode": false, "paid": true, "status": "paid", "amount": 100, "currency": "usd", "refunded": false, "source": { "id": "card_6HAwNGtbdzFdq0", "object": "card", "last4": "4242", "brand": "Visa", "funding": "credit", "exp_month": 12, "exp_year": 2015, "fingerprint": "I2nSF7gS79j9Zhei", "country": "US", "name": null, "address_line1": null, "address_line2": null, "address_city": null, "address_state": null, "address_zip": null, "address_country": null, "cvc_check": "pass", "address_line1_check": null, "address_zip_check": null, "dynamic_last4": null, "metadata": {}, "customer": null }, "captured": true, "card": { "id": "card_6HAwNGtbdzFdq0", "object": "card", "last4": "4242", "brand": "Visa", "funding": "credit", "exp_month": 12, "exp_year": 2015, "fingerprint": "I2nSF7gS79j9Zhei", "country": "US", "name": null, "address_line1": null, "address_line2": null, "address_city": null, "address_state": null, "address_zip": null, "address_country": null, "cvc_check": "pass", "address_line1_check": null, "address_zip_check": null, "dynamic_last4": null, "metadata": {}, "customer": null }, "balance_transaction": "txn_6HAw4bAUUZ6trA", "failure_message": null, "failure_code": null, "amount_refunded": 0, "customer": null, "invoice": null, "description": "PhillipSenn#gmail.com", "dispute": null, "metadata": {}, "statement_descriptor": null, "fraud_details": {}, "receipt_email": null, "receipt_number": null, "shipping": null, "destination": null, "application_fee": null, "refunds": { "object": "list", "total_count": 0, "has_more": false, "url": "/v1/charges/ch_6HAwRK92OsQPoA/refunds", "data": [] } }';
writeOutput(isJSon(json));
writeDump(DeserializeJSON(json));
</cfscript>
Run: http://trycf.com/gist/cb798ff697ac80396284/acf11

Related

Cannot See Workflows while Running Temporal on AWS ECS with AWS Elasticsearch

I deployed Temporal along with Temporal Web on AWS ECS. I replicated the configuration using this Docker Compose file: https://github.com/temporalio/docker-compose/blob/main/docker-compose.yml
I used this configuration file: https://github.com/temporalio/docker-compose/blob/main/dynamicconfig/development_es.yaml
For Elasticsearch, I used a single node password enabled AWS Elasticsearch domain having ES v7.10.
For Postgres, I used a single instance password enabled AWS RDS database having Postgres v13.3.
My task definition for Temporal is as follows:
{
"ipcMode": null,
"executionRoleArn": "arn:aws:iam::999999999999:role/dev-ecs-task-execution-role",
"containerDefinitions": [
{
"dnsSearchDomains": null,
"environmentFiles": null,
"logConfiguration": {
"logDriver": "awslogs",
"secretOptions": null,
"options": {
"awslogs-group": "awslogs-dev",
"awslogs-region": "eu-central-1",
"awslogs-create-group": "true",
"awslogs-stream-prefix": "awslogs-temporal"
}
},
"entryPoint": [],
"portMappings": [
{
"hostPort": 7233,
"protocol": "tcp",
"containerPort": 7233
}
],
"command": [],
"linuxParameters": null,
"cpu": 32,
"environment": [
{
"name": "DB",
"value": "postgresql"
},
{
"name": "DB_PORT",
"value": "5432"
},
{
"name": "DYNAMIC_CONFIG_FILE_PATH",
"value": "/temporal/development_es.yaml"
},
{
"name": "ENABLE_ES",
"value": "true"
},
{
"name": "ES_PORT",
"value": "443"
},
{
"name": "ES_SCHEME",
"value": "https"
},
{
"name": "ES_VERSION",
"value": "v7"
},
{
"name": "LOG_LEVEL",
"value": "info"
},
{
"name": "SERVICES",
"value": "history,matching,frontend,worker"
}
],
"resourceRequirements": null,
"ulimits": [],
"dnsServers": null,
"mountPoints": [
{
"readOnly": true,
"containerPath": "/temporal",
"sourceVolume": "configVolume"
}
],
"workingDirectory": null,
"secrets": [
{
"valueFrom": "arn:aws:ssm:eu-central-1:999999999999:parameter/docker/dev/temporal_POSTGRES_USERNAME",
"name": "POSTGRES_USER"
},
{
"valueFrom": "arn:aws:ssm:eu-central-1:999999999999:parameter/docker/dev/temporal_POSTGRES_PASSWORD",
"name": "POSTGRES_PWD"
},
{
"valueFrom": "arn:aws:ssm:eu-central-1:999999999999:parameter/docker/dev/temporal_POSTGRES_HOST",
"name": "POSTGRES_SEEDS"
},
{
"valueFrom": "arn:aws:ssm:eu-central-1:999999999999:parameter/docker/dev/temporal_ES_HOST",
"name": "ES_SEEDS"
},
{
"valueFrom": "arn:aws:ssm:eu-central-1:999999999999:parameter/docker/dev/temporal_ES_USERNAME",
"name": "ES_USER"
},
{
"valueFrom": "arn:aws:ssm:eu-central-1:999999999999:parameter/docker/dev/temporal_ES_PASSWORD",
"name": "ES_PWD"
}
],
"dockerSecurityOptions": null,
"memory": 256,
"memoryReservation": 128,
"volumesFrom": [],
"stopTimeout": 60,
"image": "temporalio/auto-setup:1.15.0",
"startTimeout": null,
"firelensConfiguration": null,
"dependsOn": null,
"disableNetworking": null,
"interactive": null,
"healthCheck": null,
"essential": true,
"links": null,
"hostname": null,
"extraHosts": null,
"pseudoTerminal": null,
"user": null,
"readonlyRootFilesystem": null,
"dockerLabels": null,
"systemControls": null,
"privileged": null,
"name": "temporal"
}
],
"placementConstraints": [],
"memory": null,
"taskRoleArn": null,
"compatibilities": [
"EC2"
],
"taskDefinitionArn": "arn:aws:ecs:eu-central-1:999999999999:task-definition/temporal-dev:36",
"family": "temporal-dev",
"requiresAttributes": [
{
"targetId": null,
"targetType": null,
"value": null,
"name": "com.amazonaws.ecs.capability.logging-driver.awslogs"
},
{
"targetId": null,
"targetType": null,
"value": null,
"name": "ecs.capability.execution-role-awslogs"
},
{
"targetId": null,
"targetType": null,
"value": null,
"name": "ecs.capability.efsAuth"
},
{
"targetId": null,
"targetType": null,
"value": null,
"name": "com.amazonaws.ecs.capability.docker-remote-api.1.19"
},
{
"targetId": null,
"targetType": null,
"value": null,
"name": "ecs.capability.efs"
},
{
"targetId": null,
"targetType": null,
"value": null,
"name": "com.amazonaws.ecs.capability.docker-remote-api.1.21"
},
{
"targetId": null,
"targetType": null,
"value": null,
"name": "ecs.capability.container-ordering"
},
{
"targetId": null,
"targetType": null,
"value": null,
"name": "com.amazonaws.ecs.capability.docker-remote-api.1.25"
},
{
"targetId": null,
"targetType": null,
"value": null,
"name": "ecs.capability.secrets.ssm.environment-variables"
},
{
"targetId": null,
"targetType": null,
"value": null,
"name": "com.amazonaws.ecs.capability.docker-remote-api.1.18"
},
{
"targetId": null,
"targetType": null,
"value": null,
"name": "ecs.capability.task-eni"
},
{
"targetId": null,
"targetType": null,
"value": null,
"name": "com.amazonaws.ecs.capability.docker-remote-api.1.29"
}
],
"pidMode": null,
"requiresCompatibilities": [
"EC2"
],
"networkMode": "awsvpc",
"runtimePlatform": null,
"cpu": null,
"revision": 36,
"status": "ACTIVE",
"inferenceAccelerators": null,
"proxyConfiguration": null,
"volumes": [
{
"fsxWindowsFileServerVolumeConfiguration": null,
"efsVolumeConfiguration": {
"transitEncryptionPort": null,
"fileSystemId": "fs-99999999",
"authorizationConfig": null,
"transitEncryption": null,
"rootDirectory": "temporal"
},
"name": "configVolume",
"host": null,
"dockerVolumeConfiguration": null
}
]
}
My task definition for Temporal Web is as follows:
{
"ipcMode": null,
"executionRoleArn": "arn:aws:iam::999999999999:role/dev-ecs-task-execution-role",
"containerDefinitions": [
{
"dnsSearchDomains": null,
"environmentFiles": null,
"logConfiguration": {
"logDriver": "awslogs",
"secretOptions": null,
"options": {
"awslogs-group": "awslogs-dev",
"awslogs-region": "eu-central-1",
"awslogs-create-group": "true",
"awslogs-stream-prefix": "awslogs-temporal-web"
}
},
"entryPoint": [],
"portMappings": [
{
"hostPort": 8088,
"protocol": "tcp",
"containerPort": 8088
}
],
"command": [],
"linuxParameters": null,
"cpu": 32,
"environment": [
{
"name": "TEMPORAL_GRPC_ENDPOINT",
"value": "temporal.dev-local:7233"
},
{
"name": "TEMPORAL_PERMIT_WRITE_API",
"value": "true"
}
],
"resourceRequirements": null,
"ulimits": [],
"dnsServers": null,
"mountPoints": [],
"workingDirectory": null,
"secrets": [],
"dockerSecurityOptions": null,
"memory": 256,
"memoryReservation": 128,
"volumesFrom": [],
"stopTimeout": 60,
"image": "temporalio/web:1.13.0",
"startTimeout": null,
"firelensConfiguration": null,
"dependsOn": null,
"disableNetworking": null,
"interactive": null,
"healthCheck": null,
"essential": true,
"links": null,
"hostname": null,
"extraHosts": null,
"pseudoTerminal": null,
"user": null,
"readonlyRootFilesystem": null,
"dockerLabels": null,
"systemControls": null,
"privileged": null,
"name": "temporal-web"
}
],
"placementConstraints": [],
"memory": null,
"taskRoleArn": null,
"compatibilities": [
"EC2"
],
"taskDefinitionArn": "arn:aws:ecs:eu-central-1:999999999999:task-definition/temporal-web-dev:7",
"family": "temporal-web-dev",
"requiresAttributes": [
{
"targetId": null,
"targetType": null,
"value": null,
"name": "com.amazonaws.ecs.capability.logging-driver.awslogs"
},
{
"targetId": null,
"targetType": null,
"value": null,
"name": "ecs.capability.execution-role-awslogs"
},
{
"targetId": null,
"targetType": null,
"value": null,
"name": "com.amazonaws.ecs.capability.docker-remote-api.1.19"
},
{
"targetId": null,
"targetType": null,
"value": null,
"name": "com.amazonaws.ecs.capability.docker-remote-api.1.21"
},
{
"targetId": null,
"targetType": null,
"value": null,
"name": "ecs.capability.container-ordering"
},
{
"targetId": null,
"targetType": null,
"value": null,
"name": "com.amazonaws.ecs.capability.docker-remote-api.1.18"
},
{
"targetId": null,
"targetType": null,
"value": null,
"name": "ecs.capability.task-eni"
},
{
"targetId": null,
"targetType": null,
"value": null,
"name": "com.amazonaws.ecs.capability.docker-remote-api.1.29"
}
],
"pidMode": null,
"requiresCompatibilities": [
"EC2"
],
"networkMode": "awsvpc",
"runtimePlatform": null,
"cpu": null,
"revision": 7,
"status": "ACTIVE",
"inferenceAccelerators": null,
"proxyConfiguration": null,
"volumes": []
}
I'm able to run those 2 containers successfully and temporal connects to and writes data on Postgres and Elasticsearch successfully.
The issue is, I'm not able to see any workflows on the Temporal Web UI neither in my created namespace nor under the default namespace but I can see data on Elasticsearch.
I'm not able to find any error logs, I only see info logs under AWS CloudWatch for both Temporal and Temporal Web UI.
What did I miss? What's the actual issue? Is there any tutorial or guide available to make it work on AWS ECS with AWS RDS Postgres and AWS Elasticsearch using dynamic configuration?
Note: When I run it locally using docker-compose, it works.
I checked the temporal-system namespace here and I was able to see the workflows: https://temporal-dev.example.com/namespaces/temporal-system/workflows?range=last-30-days&status=ALL
I can also see workflows in our namespaces.
I did the following things:
I enabled authentication (username and password) on Elasticsearch for successful connectivity.
I deleted the temporal index from Elasticsearch.
I upgraded the temporal version to v1.15.0 by using the following image: temporalio/auto-setup:1.15.0
It was 1.13.1 before.
I deleted the temporal databases from Postgres.
I restarted the temporal ECS services and the services that create namespaces.
It worked.

Parsing complex JSON using Kinesis Analytics

I have the following JSON stream coming from Twitter.
{
"created_at": "Thu Sep 27 21:02:00 +0000 2018",
"id": 1045418301336244224,
"id_str": "1045418301336244224",
"text": "Conditional Branching Now Supported in AWS Systems Manager Automation - #awscloud #amazon #aws",
"source": "Buffer",
"truncated": false,
"in_reply_to_status_id": null,
"in_reply_to_status_id_str": null,
"in_reply_to_user_id": null,
"in_reply_to_user_id_str": null,
"in_reply_to_screen_name": null,
"user": {
"id": 14687423,
"id_str": "14687423",
"name": "Casey Becking",
"screen_name": "caseybecking",
"location": "Huntington Beach, CA",
"url": "http://caseybecking.com",
"description": "I do stuff with computers for #rackspace , geek at heart! play and watch to much hockey, someday I'll make a personal website.",
"translator_type": "none",
"protected": false,
"verified": false,
"followers_count": 4191,
"friends_count": 2412,
"listed_count": 90,
"favourites_count": 794,
"statuses_count": 12995,
"created_at": "Wed May 07 15:03:23 +0000 2008",
"utc_offset": null,
"time_zone": null,
"geo_enabled": true,
"lang": "en",
"contributors_enabled": false,
"is_translator": false,
"profile_background_color": "000000",
"profile_background_image_url": "http://abs.twimg.com/images/themes/theme15/bg.png",
"profile_background_image_url_https": "https://abs.twimg.com/images/themes/theme15/bg.png",
"profile_background_tile": false,
"profile_link_color": "ABB8C2",
"profile_sidebar_border_color": "000000",
"profile_sidebar_fill_color": "000000",
"profile_text_color": "000000",
"profile_use_background_image": false,
"profile_image_url": "http://pbs.twimg.com/profile_images/981617292546060289/RMX0GQFe_normal.jpg",
"profile_image_url_https": "https://pbs.twimg.com/profile_images/981617292546060289/RMX0GQFe_normal.jpg",
"profile_banner_url": "https://pbs.twimg.com/profile_banners/14687423/1439137746",
"default_profile": false,
"default_profile_image": false,
"following": null,
"follow_request_sent": null,
"notifications": null
},
"geo": null,
"coordinates": null,
"place": null,
"contributors": null,
"is_quote_status": false,
"quote_count": 0,
"reply_count": 0,
"retweet_count": 0,
"favorite_count": 0,
"entities": {
"hashtags": [{
"text": "amazon",
"indices": [106, 113]
}, {
"text": "aws",
"indices": [114, 118]
}],
"urls": [{
"url": "",
"expanded_url": "https://buff.ly/2zwRyBx",
"display_url": "buff.ly/2zwRyBx",
"indices": [72, 95]
}],
"user_mentions": [{
"screen_name": "awscloud",
"name": "Amazon Web Services",
"id": 66780587,
"id_str": "66780587",
"indices": [96, 105]
}],
"symbols": []
},
"favorited": false,
"retweeted": false,
"possibly_sensitive": false,
"filter_level": "low",
"lang": "en",
"timestamp_ms": "1538082120628",
"emoticons": [],
"sentiments": "Neutral"
}
How do I parse, analyze and process this JSON using Kinesis Analytics?
The arrays should be flattened and this is very doable in Hive but need to do the same in Kinesis Analytics.

NaN userId while setting userContext loopback

I have a model UserB2b extended from User. I have enabled authorization using server.authEnabled in the boot script so that all requests pass through the auth middleware.
Problem: Whenever I have an non-numeric username in my UserB2b model, I get a NaN userId from AccessToken.findForRequest in loopback/common/model/access-token.js.
Here are my models.
AccessToken
{
"name": "AccessToken",
"base": "AccessToken",
"idInjection": false,
"options": {
"validateUpsert": true
},
"mysql": {
"table": "AccessToken"
},
"properties": {
"ttl": {
"type": "Number",
"required": false,
"length": null,
"precision": 10,
"scale": 0,
"mysql": {
"columnName": "ttl",
"dataType": "int",
"dataLength": null,
"dataPrecision": 10,
"dataScale": 0,
"nullable": "Y"
},
"_selectable": true
},
"created": {
"type": "Date",
"required": false,
"length": null,
"precision": null,
"scale": null,
"mysql": {
"columnName": "created",
"dataType": "datetime",
"dataLength": null,
"dataPrecision": null,
"dataScale": null,
"nullable": "Y"
},
"_selectable": true
},
"userId": {
"type": "String",
"required": false,
"length": null,
"precision": 10,
"scale": 0,
"mysql": {
"columnName": "userId",
"dataType": "varchar",
"dataLength": null,
"dataPrecision": 10,
"dataScale": 0,
"nullable": "Y"
},
"_selectable": true
},
"id": {
"type": "String",
"id": true,
"required": false,
"length": 255,
"precision": null,
"scale": null,
"mysql": {
"columnName": "id",
"dataType": "varchar",
"dataLength": 255,
"dataPrecision": null,
"dataScale": null,
"nullable": "N"
},
"_selectable": false
},
"model": {
"type": "string",
"id": false,
"length": 100,
"precision": null,
"scale": null,
"mysql": {
"columnName": "model",
"dataType": "varchar",
"dataLength": 100,
"dataPrecision": null,
"dataScale": null,
"nullable": "N"
},
"_selectable": false
}
},
"validations": [],
"relations": {
"userB2B":{
"type":"belongsTo",
"model":"UserB2b",
"foreignKey":"userId"
}
},
"acls": [
{
"accessType": "*",
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "DENY"
},
{
"accessType": "*",
"principalType": "ROLE",
"principalId":"$authenticated",
"permission": "ALLOW"
}
],
"methods": {}
}
UserB2b
{
"name": "UserB2b",
"base": "User",
"idInjection": false,
"options": {
"validateUpsert": true
},
"mysql": {
"table": "user_b2b"
},
"scope": {
"where": {
"deleted": 0
}
},
"properties": {
"username": {
"type": "String",
"id": true,
"required": true,
"length": 255,
"precision": null,
"scale": null,
"mysql": {
"columnName": "username",
"dataType": "varchar",
"dataLength": 255,
"dataPrecision": null,
"dataScale": null,
"nullable": "N"
},
"_selectable": false
},
"password": {
"type": "String",
"required": true,
"length": 1000,
"precision": null,
"scale": null,
"mysql": {
"columnName": "password",
"dataType": "varchar",
"dataLength": 1000,
"dataPrecision": null,
"dataScale": null,
"nullable": "N"
},
"_selectable": false
},
"name": {
"type": "String",
"required": true,
"length": 255,
"precision": null,
"scale": null,
"mysql": {
"columnName": "name",
"dataType": "varchar",
"dataLength": 255,
"dataPrecision": null,
"dataScale": null,
"nullable": "N"
},
"_selectable": false
},
"contactNumber": {
"type": "String",
"required": true,
"length": 255,
"precision": null,
"scale": null,
"mysql": {
"columnName": "contact_number",
"dataType": "varchar",
"dataLength": 255,
"dataPrecision": null,
"dataScale": null,
"nullable": "N"
},
"_selectable": false
},
"createdAt": {
"type": "Date",
"required": false,
"length": null,
"precision": null,
"scale": null,
"mysql": {
"columnName": "created_at",
"dataType": "timestamp",
"dataLength": null,
"dataPrecision": null,
"dataScale": null,
"nullable": "Y"
},
"_selectable": true
},
"updatedAt": {
"type": "Date",
"required": false,
"length": null,
"precision": null,
"scale": null,
"mysql": {
"columnName": "updated_at",
"dataType": "timestamp",
"dataLength": null,
"dataPrecision": null,
"dataScale": null,
"nullable": "Y"
},
"_selectable": true
},
"deleted": {
"type": "Number",
"required": false,
"length": null,
"precision": 3,
"scale": 0,
"mysql": {
"columnName": "deleted",
"dataType": "tinyint",
"dataLength": null,
"dataPrecision": 3,
"dataScale": 0,
"nullable": "Y"
},
"_selectable": true
},
"email": false,
"created": false,
"lastUpdated": false,
"credentials": false,
"challenges": false,
"status": false,
"verificationToken": false,
"realm": false,
"emailVerified": false
},
"validations": [],
"relations": {
"accessTokens": {
"type": "hasMany",
"model": "Accesstoken",
"foreignKey": "userName"
}
},
"methods": {}
}
Here is the raw packet that I get from the debugger
<-- RowDataPacket
RowDataPacket {
id: 'BJVqc7CtRXzPVVtTyJqmUabijgLRRHBe3sqcCh0bh5NuGBIZCnY8nwLIGeB6dILv',
ttl: 12096000,
created: Tue May 24 2016 05:44:18 GMT+0000 (UTC),
model: 'UserB2b',
userId: 'max1' }
and the query that loopback fires after that is
SELECT `username`,`password`,`name`,`contact_number`,`created_at`,`updated_at`,`deleted` FROM `user_b2b` WHERE (`username`=?) AND (`deleted`=?) ORDER BY `username` LIMIT 1, params: ["NaN",0]
Is there something that needs to be corrected here ?
it seems something wrong here in your access token:
"userId": {
"type": "String",
"required": false,
"length": null,
"precision": 10,
"scale": 0,
"mysql": {
"columnName": "userId",
"dataType": "int",
The type you are using int and you are passing as varchar item and this will throw exception that string is not a number(NAN).
Either change the target type to string/varchar or change the source data type that you are using that matched with target.
Hope this will help you.

Insert does not work on model with composite id in loopback

I have a table named Xml_Mapping with composit ID on MYSQL.
When i try to insert into table; in runtime or from StrongLoop API Explorer, i could not insert.
When i debug, i see wrong insert sql :
INSERT INTO `Xml_Mapping`(`SiteId`,`SystemKeyId`,`TargetKey`) VALUES(1,1,'stockcode')
ON DUPLICATE KEY UPDATE
as you can see, "UPDATE" sql was not completed. So it could not be executed...
How can i solve this problem?
Xml_Mapping Table:
SiteId INT NOT NULL,
SystemKeyId INT NOT NULL,
TargetKey VARCHAR(100) NOT NULL,
PRIMARY KEY (SiteId, SystemKeyId, TargetKey),
CONSTRAINT XML_MAPPING_fk1 FOREIGN KEY (SiteId) REFERENCES site (Id),
INDEX XML_MAPPING_fk1 (SiteId)
Xml-mapping.json :
{
"name": "XmlMapping",
"base": "PersistedModel",
"idInjection": false,
"options": {
"validateUpsert": true
},
"mysql": {
"schema": "uygunca",
"table": "Xml_Mapping"
},
"properties": {
"SiteId": {
"type": "Number",
"id": 1,
"required": true,
"length": null,
"precision": 10,
"scale": 0,
"mysql": {
"columnName": "SiteId",
"dataType": "int",
"dataLength": null,
"dataPrecision": 10,
"dataScale": 0,
"nullable": "N"
},
"_selectable": false
},
"SystemKeyId": {
"type": "Number",
"id": 2,
"required": true,
"length": null,
"precision": 10,
"scale": 0,
"mysql": {
"columnName": "SystemKeyId",
"dataType": "int",
"dataLength": null,
"dataPrecision": 10,
"dataScale": 0,
"nullable": "N"
},
"_selectable": false
},
"TargetKey": {
"type": "String",
"id": 3,
"required": true,
"length": 100,
"precision": null,
"scale": null,
"mysql": {
"columnName": "TargetKey",
"dataType": "varchar",
"dataLength": 100,
"dataPrecision": null,
"dataScale": null,
"nullable": "N"
},
"_selectable": false
}
},
"validations": [],
"relations": {},
"acls": [],
"methods": []
}
Alter your table Xml_Mapping and set autoincrement for field SiteId
and you don't need to provide SiteId in JSON
Run
ALTER TABLE `Xml_Mapping`
MODIFY `SiteId` int(10) NOT NULL AUTO_INCREMENT
Change your model Xml-mapping.json : and set properties for SiteId "required": false,
It should be like
{
"name": "XmlMapping",
"base": "PersistedModel",
"idInjection": false,
"options": {
"validateUpsert": true
},
"mysql": {
"schema": "uygunca",
"table": "Xml_Mapping"
},
"properties": {
"SiteId": {
"type": "Number",
"id": 1,
"required": false,
"length": null,
"precision": 10,
"scale": 0,
"mysql": {
"columnName": "SiteId",
"dataType": "int",
"dataLength": null,
"dataPrecision": 10,
"dataScale": 0,
"nullable": "N"
},
"_selectable": false
},
"SystemKeyId": {
"type": "Number",
"id": 2,
"required": true,
"length": null,
"precision": 10,
"scale": 0,
"mysql": {
"columnName": "SystemKeyId",
"dataType": "int",
"dataLength": null,
"dataPrecision": 10,
"dataScale": 0,
"nullable": "N"
},
"_selectable": false
},
"TargetKey": {
"type": "String",
"id": 3,
"required": true,
"length": 100,
"precision": null,
"scale": null,
"mysql": {
"columnName": "TargetKey",
"dataType": "varchar",
"dataLength": 100,
"dataPrecision": null,
"dataScale": null,
"nullable": "N"
},
"_selectable": false
}
},
"validations": [],
"relations": {},
"acls": [],
"methods": []
}
and then use your JSON as
{
"SystemKeyId": 1,
"TargetKey": 'stockcode'
}

Notepad++ close non-whitespace

I have a Tweepy Stream Api json file that is included 33K tweets. All of them have non-whitespace space that I couldn't find solution. If you use copy and past it to pro.jsonlint.com, you can see that line 217 has "EOF" problem. I can fix them using notepad++ but first I need to understand that what is the problem and how I can fix it?
If somebody can tell me where is the EOF problem and how fix it with notepad++.
Thanks,
{
"created_at": "Tue Mar 31 20:50:08 +0000 2015",
"id": 583008398612029440,
"id_str": "583008398612029440",
"text": "RT #kamalakmustafa: Hain bir sald\u0131r\u0131 sonucu \u015fehit d\u00fc\u015fen Savc\u0131m\u0131z #MehmetSelimKiraz 'a Allah'tan rahmet, ailesine sab\u0131rlar diliyorum. Millet\u2026",
"source": "\u003ca href=\"http:\/\/www.twitter.com\" rel=\"nofollow\"\u003eTwitter for Windows Phone\u003c\/a\u003e",
"truncated": false,
"in_reply_to_status_id": null,
"in_reply_to_status_id_str": null,
"in_reply_to_user_id": null,
"in_reply_to_user_id_str": null,
"in_reply_to_screen_name": null,
"user": {
"id": 1337409816,
"id_str": "1337409816",
"name": "Atakan \u00c7etin",
"screen_name": "BrownnChild",
"location": "",
"url": null,
"description": "Bir nefesine bile h\u00fckmedemedi\u011fimiz bu d\u00fcnya i\u00e7in boyun mu b\u00fckece\u011fiz? M\u0130LL\u0130 G\u00d6R\u00dc\u015e!",
"protected": false,
"verified": false,
"followers_count": 246,
"friends_count": 116,
"listed_count": 0,
"favourites_count": 1077,
"statuses_count": 2613,
"created_at": "Mon Apr 08 19:31:06 +0000 2013",
"utc_offset": 10800,
"time_zone": "Athens",
"geo_enabled": true,
"lang": "tr",
"contributors_enabled": false,
"is_translator": false,
"profile_background_color": "131516",
"profile_background_image_url": "http:\/\/abs.twimg.com\/images\/themes\/theme14\/bg.gif",
"profile_background_image_url_https": "https:\/\/abs.twimg.com\/images\/themes\/theme14\/bg.gif",
"profile_background_tile": true,
"profile_link_color": "009999",
"profile_sidebar_border_color": "EEEEEE",
"profile_sidebar_fill_color": "EFEFEF",
"profile_text_color": "333333",
"profile_use_background_image": true,
"profile_image_url": "http:\/\/pbs.twimg.com\/profile_images\/579347764670296064\/6yuzFJPG_normal.jpg",
"profile_image_url_https": "https:\/\/pbs.twimg.com\/profile_images\/579347764670296064\/6yuzFJPG_normal.jpg",
"profile_banner_url": "https:\/\/pbs.twimg.com\/profile_banners\/1337409816\/1427653680",
"default_profile": false,
"default_profile_image": false,
"following": null,
"follow_request_sent": null,
"notifications": null
},
"geo": null,
"coordinates": null,
"place": null,
"contributors": null,
"retweeted_status": {
"created_at": "Tue Mar 31 20:38:15 +0000 2015",
"id": 583005408828252160,
"id_str": "583005408828252160",
"text": "Hain bir sald\u0131r\u0131 sonucu \u015fehit d\u00fc\u015fen Savc\u0131m\u0131z #MehmetSelimKiraz 'a Allah'tan rahmet, ailesine sab\u0131rlar diliyorum. Milletimizin ba\u015f\u0131 sa\u011folsun.",
"source": "\u003ca href=\"http:\/\/twitter.com\/download\/android\" rel=\"nofollow\"\u003eTwitter for Android\u003c\/a\u003e",
"truncated": false,
"in_reply_to_status_id": null,
"in_reply_to_status_id_str": null,
"in_reply_to_user_id": null,
"in_reply_to_user_id_str": null,
"in_reply_to_screen_name": null,
"user": {
"id": 338288811,
"id_str": "338288811",
"name": "Mustafa Kamalak",
"screen_name": "kamalakmustafa",
"location": "Ankara, T\u00fcrkiye",
"url": "http:\/\/www.saadet.org.tr\/kisi\/mustafa-kamalak",
"description": "Saadet Partisi Genel Ba\u015fkan\u0131\n Prof. Dr. Mustafa Kamalak",
"protected": false,
"verified": false,
"followers_count": 52358,
"friends_count": 2,
"listed_count": 163,
"favourites_count": 0,
"statuses_count": 1574,
"created_at": "Tue Jul 19 10:48:16 +0000 2011",
"utc_offset": 10800,
"time_zone": "Istanbul",
"geo_enabled": false,
"lang": "tr",
"contributors_enabled": false,
"is_translator": false,
"profile_background_color": "FFFFFF",
"profile_background_image_url": "http:\/\/pbs.twimg.com\/profile_background_images\/378800000181217982\/FBktDfqo.jpeg",
"profile_background_image_url_https": "https:\/\/pbs.twimg.com\/profile_background_images\/378800000181217982\/FBktDfqo.jpeg",
"profile_background_tile": false,
"profile_link_color": "0084B4",
"profile_sidebar_border_color": "000000",
"profile_sidebar_fill_color": "DDFFCC",
"profile_text_color": "333333",
"profile_use_background_image": true,
"profile_image_url": "http:\/\/pbs.twimg.com\/profile_images\/436119860225908737\/76GmiIPj_normal.jpeg",
"profile_image_url_https": "https:\/\/pbs.twimg.com\/profile_images\/436119860225908737\/76GmiIPj_normal.jpeg",
"profile_banner_url": "https:\/\/pbs.twimg.com\/profile_banners\/338288811\/1423922000",
"default_profile": false,
"default_profile_image": false,
"following": null,
"follow_request_sent": null,
"notifications": null
},
"geo": null,
"coordinates": null,
"place": null,
"contributors": null,
"retweet_count": 122,
"favorite_count": 152,
"entities": {
"hashtags": [
{
"text": "MehmetSelimKiraz",
"indices": [
45,
62
]
}
],
"trends": [
],
"urls": [
],
"user_mentions": [
],
"symbols": [
]
},
"favorited": false,
"retweeted": false,
"possibly_sensitive": false,
"filter_level": "low",
"lang": "tr"
},
"retweet_count": 0,
"favorite_count": 0,
"entities": {
"hashtags": [
{
"text": "MehmetSelimKiraz",
"indices": [
65,
82
]
}
],
"trends": [
],
"urls": [
],
"user_mentions": [
{
"screen_name": "kamalakmustafa",
"name": "Mustafa Kamalak",
"id": 338288811,
"id_str": "338288811",
"indices": [
3,
18
]
}
],
"symbols": [
]
},
"favorited": false,
"retweeted": false,
"possibly_sensitive": false,
"filter_level": "low",
"lang": "tr",
"timestamp_ms": "1427835008658"
}
{
"created_at": "Tue Mar 31 20:50:08 +0000 2015",
"id": 583008398649769984,
"id_str": "583008398649769984",
"text": "RT #BekirDeveli: #MehmetSelimKiraz",
"source": "\u003ca href=\"http:\/\/twitterhizmetcisi.com\" rel=\"nofollow\"\u003eTranslation Mobile\u003c\/a\u003e",
"truncated": false,
"in_reply_to_status_id": null,
"in_reply_to_status_id_str": null,
"in_reply_to_user_id": null,
"in_reply_to_user_id_str": null,
"in_reply_to_screen_name": null,
"user": {
"id": 1284184062,
"id_str": "1284184062",
"name": "K\u00fcrsad Celik",
"screen_name": "KrsadC",
"location": "Istanbul-Den\u0131zl\u0131",
"url": null,
"description": null,
"protected": false,
"verified": false,
"followers_count": 166,
"friends_count": 452,
"listed_count": 1,
"favourites_count": 1892,
"statuses_count": 2723,
"created_at": "Wed Mar 20 20:23:46 +0000 2013",
"utc_offset": 10800,
"time_zone": "Athens",
"geo_enabled": true,
"lang": "tr",
"contributors_enabled": false,
"is_translator": false,
"profile_background_color": "FFF04D",
"profile_background_image_url": "http:\/\/pbs.twimg.com\/profile_background_images\/378800000168605771\/dgYo8Miy.jpeg",
"profile_background_image_url_https": "https:\/\/pbs.twimg.com\/profile_background_images\/378800000168605771\/dgYo8Miy.jpeg",
"profile_background_tile": true,
"profile_link_color": "0099CC",
"profile_sidebar_border_color": "FFFFFF",
"profile_sidebar_fill_color": "F6FFD1",
"profile_text_color": "333333",
"profile_use_background_image": true,
"profile_image_url": "http:\/\/pbs.twimg.com\/profile_images\/437899583348572160\/FamxSRwB_normal.jpeg",
"profile_image_url_https": "https:\/\/pbs.twimg.com\/profile_images\/437899583348572160\/FamxSRwB_normal.jpeg",
"profile_banner_url": "https:\/\/pbs.twimg.com\/profile_banners\/1284184062\/1393238552",
"default_profile": false,
"default_profile_image": false,
"following": null,
"follow_request_sent": null,
"notifications": null
},
"geo": null,
"coordinates": null,
"place": null,
"contributors": null,
"retweeted_status": {
"created_at": "Tue Mar 31 20:39:47 +0000 2015",
"id": 583005791340404737,
"id_str": "583005791340404737",
"text": "#MehmetSelimKiraz",
"source": "\u003ca href=\"http:\/\/twitter.com\/download\/iphone\" rel=\"nofollow\"\u003eTwitter for iPhone\u003c\/a\u003e",
"truncated": false,
"in_reply_to_status_id": null,
"in_reply_to_status_id_str": null,
"in_reply_to_user_id": null,
"in_reply_to_user_id_str": null,
"in_reply_to_screen_name": null,
"user": {
"id": 607600160,
"id_str": "607600160",
"name": "Bekir Develi",
"screen_name": "BekirDeveli",
"location": "\u0130stanbul\/Turkey",
"url": "http:\/\/www.bekirdeveli.com",
"description": null,
"protected": false,
"verified": false,
"followers_count": 225574,
"friends_count": 2{
"created_at": "Tue Mar 31 20:50:14 +0000 2015",
"id": 583008421152198656,
"id_str": "583008421152198656",
"text": "#mehmetselimkiraz https:\/\/t.co\/ly9MROZ6Yg",
"source": "\u003ca href=\"http:\/\/instagram.com\" rel=\"nofollow\"\u003eInstagram\u003c\/a\u003e",
"truncated": false,
"in_reply_to_status_id": null,
"in_reply_to_status_id_str": null,
"in_reply_to_user_id": null,
"in_reply_to_user_id_str": null,
"in_reply_to_screen_name": null,
"user": {
"id": 110186170,
"id_str": "110186170",
"name": "\u015eeyma Ceylan",
"screen_name": "cylnm",
"location": "ceylan",
"url": null,
"description": "\u0648\u0642\u062f\u0645 \u0643\u0644 \u0627\u0644\u0627\u0646\u0632\u0639\u0627\u062c \u0631\u0627\u062d\u0629 \u0627\u0644\u0644\u0647I http:\/\/Instagram.com\/seymaceylan_",
"protected": false,
"verified": false,
"followers_count": 1759,
"friends_count": 780,
"listed_count": 15,
"favourites_count": 7472,
"statuses_count": 9036,
"created_at": "Sun Jan 31 17:13:48 +0000 2010",
"utc_offset": -36000,
"time_zone": "Hawaii",
"geo_enabled": true,
"lang": "tr",
"contributors_enabled": false,
"is_translator": false,
"profile_background_color": "FF6699",
"profile_background_image_url": "http:\/\/pbs.twimg.com\/profile_background_images\/866467818\/24dcf5a87af2b92f9ff76fead916e4ef.jpeg",
"profile_background_image_url_https": "https:\/\/pbs.twimg.com\/profile_background_images\/866467818\/24dcf5a87af2b92f9ff76fead916e4ef.jpeg",
"profile_background_tile": true,
"profile_link_color": "9266CC",
"profile_sidebar_border_color": "FFFFFF",
"profile_sidebar_fill_color": "E5507E",
"profile_text_color": "362720",
"profile_use_background_image": true,
"profile_image_url": "http:\/\/pbs.twimg.com\/profile_images\/574664598248419329\/Budj4Oq3_normal.jpeg",
"profile_image_url_https": "https:\/\/pbs.twimg.com\/profile_images\/574664598248419329\/Budj4Oq3_normal.jpeg",
"profile_banner_url": "https:\/\/pbs.twimg.com\/profile_banners\/110186170\/1410798690",
"default_profile": false,
"default_profile_image": false,
"following": null,
"follow_request_sent": null,
"notifications": null
},
"geo": null,
"coordinates": null,
"place": null,
"contributors": null,
"retweet_count": 0,
"favorite_count": 0,
"entities": {
"hashtags": [
{
"text": "mehmetselimkiraz",
"indices": [
0,
17
]
}
],
"trends": [
],
"urls": [
{
"url": "https:\/\/t.co\/ly9MROZ6Yg",
"expanded_url": "https:\/\/instagram.com\/p\/05-6PQPQ-j\/",
"display_url": "instagram.com\/p\/05-6PQPQ-j\/",
"indices": [
18,
41
]
}
],
"user_mentions": [
],
"symbols": [
]
},
"favorited": false,
"retweeted": false,
"possibly_sensitive": true,
"filter_level": "low",
"lang": "und",
"timestamp_ms": "1427835014032"
}
You need to match individual JSON objects, and I think you can just match them and copy wherever you need using this regex:
\{(?:[^{}]+|(?0))*\}
It works in Notepad++ 6.7.5, and it will select the text from the first { up to the corresponding closing }.