MergJSON error "...unexpected token near end of file"? - json

I have the simplest of scripts in LiveCode attempting to parse a small chunk of JSON using the MergJSON library.
This is doubtless something stupid I'm doing as it's been a long day, but I just can't get the JSON parsed into a LiveCode array:
LC Script in a button called 'Connect'
function JSONToArray pJSON
local tArray,tKeys
repeat for each line tKey in mergJSONDecode(pJSON,"tArray")
put JSONToArray(tArray[tKey]) into tArray[tKey]
end repeat
return tArray
end JSONToArray
on mouseUp
put field "MyJSON" into pJSON
answer JSONToArray()
end mouseUp
My JSON
{
"firstname":"Mary",
"lastname":"Smith",
}
The Error:
Button "Connect": execution error at line n/a (External handler: exception) near "could not decode JSON: unexpected token near end of file"
Suggestions would be most welcome....
Thanks,
Steve

Mark B might have it but the other thing could be that you're not passing the parameter to JSONToArray...
put JSONToArray(pJSON) into tArray
put tArray["firstname"]

{
"firstname":"Mary",
"lastname":"Smith", <---dangling comma
}

Related

AWS Step function string/json concatenation

I have orchestrated a data pipe line using AWS Step function.
In last state I want to send a custom notification. I'm using an Intrinsic function States.Format to format my message and subject. It works fine for Context object element. Here, I have tested that in Message parameter.
But it doesn't work with input JSON. This is my input JSON
{
"job-param":{
"pipe-line-name":"My pipe line name", "other-keys":"other values"
}
}
"Success State": {
"Type": "Task",
"Resource": "arn:aws:states:::sns:publish",
"Parameters": {
"Message.$": "States.Format('Execution Id:{}, completed successfully!', $$.Execution.Id)",
"Subject.$": "States.Format('[INFO] {} completed successfully!', $.job-param.pipe-line-name)",
"TopicArn": "arn:aws:sns:us-east-1:************:sns-topic"
},
"End": true
}
While saving this state machine, it gives me following error message:
The value for the field 'Subject.$' must be a valid JSON Path
I checked Input and Result path. They have this value. I can directly use this value as parameter. This is working fine. But I can't format with other string.
"Subject.$": "$.job-param.pipe-line-name"
Alternate approach would be to call lambda to customize and trigger SNS. But I want to avoid that.
Can I request some suggestions to fix this error?
Thanks in advance!
If you want to use any name with - in your JSON then you can write your JSON Path like this:
"Subject.$": "States.Format('[INFO] {} completed successfully!', $['job-param']['pipe-line-name'])",
But it would be easier if you change your input JSON and replace - with _:
"Subject.$": "States.Format('[INFO] {} completed successfully!', $.job_param.pipe_line_name)",

How to convert a stream into an object in Ruby

I am attempting to make a PUT fetch request from my jQuery file. The server giving me a 500, as the fetch is not able to be used by my controller.
This is the stream that is being sent to my .rb file in the form of request.body:
request.body == #<StringIO:0x00005597c3b69fa8>
request.body.string == "{\"name\":\"New School\",\"office_id\":2,\"inactive\":false}"
I have tried..
load(request.body.string)
But this returns a load error:
LoadError: cannot load such file -- {"name":"New School","office_id":2,"inactive":false}
Also..
parse(request.body.string)
which results in
undefined method `parse' for #<CrEventsApp:0x00005597c3bbf098>
Is there a method that will parse this information back into a hash? I can parse through the string myself with some regex and .split() to get the data into a useable format, but I would like a more concise and robust solution.
JSON.parse should do the trick:
JSON.parse(request.body.string)
=> {"name"=>"New School", "office_id"=>2, "inactive"=>false}

JSON.parse ReferenceError: parse is not defined

I receive "ReferenceError: parse is not defined" when running the following line in Node V6.11.0 inside an express router.
router.post('/api/addComp', function(req,res) {
var tempData = JSON.parse('{"compName":"Bodhi\'s Test", "compStreet":"12312 Glendale Av", "compCity": "Los Angeles", "compZip":"90039"}');
.
.
.
}
This code tests in the browser console and should be a part of Node by default from my understanding.
The error "ReferenceError: parse is not defined" will never occur because the method parse of JSON do not exist. Since you are calling it as an function executing the error thrown would be "JSON.parse is not a function", case JSON was not instantiated it would throw "cannot call parse of undefined". Some where else in your code you have a call to parse alone, separated by a typo error, like a coma or maybe a semicolon. Usually this error will only be thrown by an undeclared variable in strict mode.
JSON.parse('{"compName":"Bodhi\'s Test", "compStreet":"12312 Glendale Av", "compCity": "Los Angeles", "compZip":"90039"}'); was working as expected. Later lines of code had incorrect syntax for parseInt()

Xtext: Testing whitespace language - missing RULE_BEGIN in JUnit

I have this fancy white space language and I'm traing to test it. For now grammar is simple (base on Terminals)
Model:
{Model}
BEGIN
package=PackageDeclaration?
class=ClassDeclaration?
END
methods+=MethodDeclaration*
;
PackageDeclaration: 'package' name=ID;
ClassDeclaration: 'class' name=ID;
MethodDeclaration: 'def' name=ID;
terminal BEGIN:
'synthetic:BEGIN';
terminal END:
'synthetic:END';
And now when it comes to JUnit:
#Test
def void packageSimpleNoErrors() {
val result = '''
package testPack
'''.parse
// Parsed without errors
result.assertNoErrors
}
Multiline string is 2x new line, tab, 'package testPack' and new line.
Checked with debug in parse method.
If I put it this way in Eclipse editor it is completly fine, no problems. But I can't make JUnit to pass this test:
java.lang.AssertionError: Expected no errors,
but got :ERROR (org.eclipse.xtext.diagnostics.Diagnostic.Syntax)
'missing RULE_BEGIN at 'package’’ on PackageDeclaration,
ERROR (org.eclipse.xtext.diagnostics.Diagnostic.Syntax)
'mismatched input '<EOF>' expecting RULE_END' on Model
For now it's not a show stoper as rest of test on this code are looking fine, but I prefer to have them all green :)
Thanks
the problem is that rich stings empty lines get lost by intent. maybe you should read the model from a file or try something
'''
«"\n"»
package testPack
'''.parse

JSON decode (JQuery and JavaScript and little PHP)

Ho ho ho, i can't decode response from php.
Json file:
{
"tableWidth":80,
"thColor": "51, 157, 221"
}
This is my awesome php function:
public function lg_getJsonSettings(){
$file = file_get_contents("settings.json",true);
$file = json_encode($file);
echo $file;
}
And JavaScript:
function lg_veriflyChanges(){
result = $.getJSON("/Controller/lg_getJsonSettings");
console.log(result);
}
On click, i call JS function. After i get response, firebug talking with me :) And what he saying ? "Zhu-zhu-zhu" :)
Seriously:
response
object console log
I try use JSON.parse(result) and $.parseJSON, but it didn't work.
Error " JSON.parse: unexpected character at line 1"
I hope, you help.
Your JSON is valid but i doubt the usage of getJSON doesn't work that way.
So, As jQuery.getJSON() documentation suggest you should use getJSON method like this ,
$.getJSON( "/Controller/lg_getJsonSettings", function(json) {
console.log(result);
});
Hope this helps.
And moreover using $.getJSON("/Controller/lg_getJsonSettings"); returns the AJAX state which is an invalid JSON,
{
readyState: 1
}
Thus causing the issue
SyntaxError: JSON.parse: unexpected character at line 1 column 2 of
the JSON data