Processed data different than raw data on Firefox - json

I came across this strange issue when using tools to prettify JSON on Firefox 65. This is my object :
{"status": 0, "message": "ok", "data": [466933532930080768, 537281936222191637]}
And as expected values are correct in RAW :
But when using the JSON or Pretty Print tools, it is not :
I tried a bunch of different JSON prettifier/formatter/validator and my object seems to be correct.
Am I missing something or did I just discovered a bug ?

ok your problem is famuos,
for fix this one you can pass string with your number and after you can use
BigInt("466933532930080768") // --> 466933532930080768n
for tacke a correct number.
do not worry about the final n JS treats it exactly like a number.
Doc
it also explains why and where does the error js

Related

Error trying to parse odata4 from API REST using NIFI

I'm using a Microsoft REST API to query a Azure application, oauth and request goes without problem.
The response from InvokeHTTP has this format
{"#odata.context":"https://****.dynamics.com/api/data/v9.1/$metadata#endpoint","value":[ here comes the actual JSON result in format {
"#odata_etag" : "W/\"555598\"", "field":"value...},...]
,"#odata.nextLink":"https://****.dynamics.com/api/data/v9.1/endpoint?$skiptoken.....}
I need to extract the nextLink for pagination and Value to continue the flow and store the result.
When I try to parse with inferAvroSchema so I can start working with it throws this error "Illegal initial character: #odata.etag"
My Idea was to inferAvroSchema, then EvaluateJsonPath to extract the odata tags and then extract the values.
I tried using EvaluateJsonPath on the result asking to create an attribute for $.#odata.context but it doesn't find the item either, I'm sure is something about the #.
I can also replace all the # of the incoming flow for another char, but don't know if that makes sense.
I'm feeling that i'm not using a correct approach, but NIFI + odata doesn't give me results on google or here.
I'm open to any suggestions!
thank you!
Schema fields cannot contain #. You could replace the #, however you must be sure not to replace it in actual content like email addresses. Another solution is to transform the API response using JoltTransformJSON processor, such that your flow can work with it:
GenerateFlowFile:
For the JoltTransformJSON processor provide following Jolt specification:
[
{
"operation": "shift",
"spec": {
"\\#odata.nextLink": "next"
}
}
]
Leave the default values for the other properties. You can play around with Jolt here: http://jolt-demo.appspot.com/
EvaluateJsonPath:
Result:
Notice that the url is now part of the flowfile attributes.
Your hunch is correct, you can only have valid characters for the field names on the schema type you are using, avro or JSON.
You could get NiFi to remove illegal characters with the replacetext proceasor, have a read here on what is valid: http://avro.apache.org/docs/current/spec.html#names

XML to JSON convertor

Was looking at a few questions in SO for a good solution for XML to JSON convertors. I Chanced upon this :
Convert xml to json with Java
This seemed to work fine for almost all of our scenarios but for the issue below!
I noticed whenever I we have an XML such as this (zero followed by a number)
<a>011</a>
this seems to be getting formatted to
{a:9}
However this seems to work fine
<a>11</a>
Whcih gets formatted to
{a:11}
This is the simple code I am using:
String sXML = "<a>011</a>";
JSONObject xmlJSONObj = XML.toJSONObject(sXML);
Any pointers?
Looks like it thinks it's an octal value, which is why you get 9, see the following article which has a similar problem:
How to force php to evaluate "011" as "11" and not "9"
When displaying the value of variable "int a = 011", I get 9. Why?

Is this json file well parsed?

I would like to know if the following message is well parsed according to json format, I think it is but the application that needs to process it complains about it with the following error
[ERR]tx data JSON file error
The code in the file is this one
{"tx":
{
"moteeui":"fa789f0000000000",
"txmsgid":"000000000152",
"trycount":"5",
"txsynch" : "false",
"ackreq" : "true",
"userdata":
{
"port":"10",
"payload":"ABCABC"
}
}
}
Thanks in advance,
regards!
I have tried also the following snippet
[{
"mote": "202020",
"payload": "ABCB",
"port": 2,
"trycount": 5,
"txmsgid": ""
}]
I have validated with JSONLint and I get an error saying
[ERR]tx data JSON parsing error: 3 object item(s) left unpacked
Does it ring a bell?
Thanks again
Yes, it is correct.
For your info, JSONLint is a good site for checking the validity of JSON.
However, you may want to rethink setting numeric values as strings. ie, it is a better idea to say:
"trycount":5
rather than
"trycount":"5"
As the former indicates to whatever application is consuming the JSON that the value should be parsed as a number.
Similarly with the boolean values, it's better practise to use:
"txsynch" : false
rather than
"txsynch" : "false"
It won't cause an error in your JSON parser to pass these as strings, it is just better practise.
The error in the parser could be for many different reasons.

Received an empty Json response using Python Requests

On zhihu, a Chinese Q&A community similar to Quora,I am writing a small program to create a list of users who follow a particular user. On the page showing this information, by scrolling down to the bottom, the browser sends a post request and receives a response in json to extend the followers list.
A snippet of the received json is (copied from firebug):
{"r":0,"msg":["<div class=\"zm-profile-card zm-profile-section-item zg-clear no-hovercard\">\n<div class=\"zg-right\">\n<button data-follow=\"m:button\" data-id=\"f09ebe71535bd89a43dd979c77cf3676\" class=\"zg-btn zg-btn-unfollow zm-rich-follow-btn small nth-0\">\u53d6\u6d88\u5173\u6ce8<\/button>.....
I have little knowledge about json but I am sure that 'msg' contains information about followers.
In my program, I use Python Requests module to send this post request to server.
payload={"method":"next","params":params,"_xsrf":_xsrf}#form data
response=session.post('http://www.zhihu.com/node/ProfileFollowersListV2',data=payload,headers=header)
response has a status code 200, but response.json() returns:
{u'msg': [], u'r': 0}
where the 'msg' is empty. Can anyone help me with this?
I encountered this very problem when I tried to get the content in the returned json file. To solve this, you just need to adjust one thing.
payload={"method":"next","params":params,"_xsrf":_xsrf}
Notice the params. You didn't show us what exactly it was. Since you and I have the same question, I'd assume that your params looks like this,
params = json.dumps({"offset":20,"order_by":"created","hash_id":"blablabla"})
Here is the big one. Your value of "offset" must be an integer, 20 in this case, but definitely not a string, say something like "20". It's really hard to tell what goes wrong when every element is double quoted.
Remember,the value of "offset" must be an integer!
"offset":20

How to Parse JSON Returned in ColdFusion

I'm sure this is a relatively simple question, but I can't seem to find a simple answer anywhere online.
I have a few lines of JSON returned by a cfhttp POST with an image URL that I'd like to parse out and display in my ColdFusion page:
{
"href": "http://server.arcgisonline.com/arcgis/rest/directories/arcgisoutput/ESRI_StreetMap_World_2D_MapServer/_ags_map734a6ad322dd493e84499d78f027d841.png",
"width": 854,
"height": 493,
"extent": {
"xmin": -8285407.015562119,
"ymin": 4944008.4197687358,
"xmax": -8220129.7934066672,
"ymax": 4981691.8747132765,
"spatialReference": {
"wkid": 102100,
"latestWkid": 3857
}
},
"scale": 288895.27714399656
}
How can I make "href"'s value a part of a variable in ColdFusion, and/or potentially have a button linked to downloading it?
EDIT: I forgot to mention that I'm using ColdFusion MX - also known as version 6 - and hence why I cannot use the DeserializeJSON listed on Adobe's page
Converts a JSON (JavaScript Object Notation) string data
representation into CFML data, such as a CFML structure or array.
https://wikidocs.adobe.com/wiki/display/coldfusionen/DeserializeJSON
Just parsing your cfhttp result with deserializeJSON()
<cfset getResult = deserializeJSON(result_Variable.filecontent)>
and you can get the href value using "#getResult.href#"
I forgot to mention that I'm using ColdFusion MX
Ah, that makes a very big difference! (Unless otherwise stated in the tags, most people will assume a more recent version, like CF9+).
JSON support was not added until CF8. If you search, there are still some older udf/cfc's for handling JSON out there. For example:
JSONDecode at http://www.cflib.org says it works with MX6
JSONUtil.cfc works with MX7+. It might work with MX6 out of the box, or with a few modifications. This thread has a description of how to encode with JSONUtil. Decoding should be equally simple. Just create an instance and invoke deserializeJSON, ie:
<!--- not tested --->
<cfset util = createObject("component", "path.to.JSONUtil")>
<cfset result = util.deSerializeJSON(yourJSONString)>
That said, ColdFusion MX is a bit long in the tooth and no longer supported. You should seriously consider upgrading or switching to the open source Railo engine.