Reading property from JSON object in Javascript with colons - json

I have a JSON object which I can console log out fine. However whenever I try to read the properties of this object I am getting "Unexpected token :" error. The json object does have a colon in it. How do i escape that colon and console.log the individual properties of the object. See that attached image for info

I think you can try out JSON serializer to get the JSON value. You can't get the JSON value without serializing it. So To serialize, you can use JsonConvert.SerializeObject("Json"). Check it out this link below for JSON serialization.
https://www.newtonsoft.com/json/help/html/SerializingJSON.htm
For serializing the JSON you should install Newtonsoft JSON package in your visual studio.

Related

Json converted object sent to kafka has quotes escaped with slashes in .net core

when I am serializing my object to json, it is added slashes to all quotes.
same way it is posted to kafka as well. I am trying to see how I can avoid slashes in the json string.
This is built in .net core
string topicmessage = JsonConvert.SerializeObject(item);
I want the json to be like
{"channel":"MOBILE","associationTime":"2022-04-19T00:12:55"}
You have to post the full code to define a bug. it could be just a visualization as a string, but a topicmessage format is ok. Otherwise it could be twice serialized. if you have an error trying to use your json, you can try this
topicmessage=JsonConvert.DeserializeObject<string>(topicmessage);

Sonar Issues/search API JSON result has single quotes

I'm using the sonarQube 6.4 web api to get a list of issues
http://sonar-server:9000/api/issues/search?componentKeys=Project_key&sinceLeakPeriod=true&statuses=OPEN,REOPENED&types=BUG
This gives me a Json object which has single quotes,
..."message":"Make this function anonymous by removing its name:
'function() {...}'."...
Because of that highlighted content in the JSON I'm unable to process the JSON from Groovy.
Is the JSON returned by the sonar is valid ?
if so, is there any way to process this kind of JSON in groovy.
Let me know if the full JSON object is needed.
According to http://json.org/ and https://jsonformatter.curiousconcept.com/ the JSON response is valid. Single quotes and brackets {} must not be escaped. The issue comes from your Groovy parser.

Need a JSON parser for Unity3d

I need to deserialize some JSON objects. I tried to use Tiny-json library, but it's too slow. I tried to use Newtonsoft.Json, but it fails in webplayer with this error:
MissingMethodException: Method not found: 'System.Collections.ObjectModel.KeyedCollection.
What JSON parser do you recommend?
You can try one of these open source solutions:
https://github.com/jacobdufault/fullserializer
https://github.com/mtschoen/JSONObject (https://www.assetstore.unity3d.com/en/#!/content/710) I am using this one most of the times, it's versbose but does its job well, not sure about performance however
Or go with paid ones:
https://www.assetstore.unity3d.com/en/#!/content/11347
Unity 5.3 added Native support of Json Serializer. It is faster than others.
JsonUtility.ToJson to convert a class to Json.
JsonUtility.FromJson to convert Json back to class.
For complete example and information regarding json arrays, see
Serialize and Deserialize Json and Json Array in Unity

Using mule expression to point to elements in JsonData Object

I have an inbound payload in JSON format. I'm converting it using the "JSON to Object" converter, and then passing on the data to a component (as a JsonData object.) My component then returns the same JsonData object with modifications. I'm trying to use the Amazon S3 component as the next step in my flow, and trying to tie the bucket name and other values to elements accessible in the JsonData object.
Here is the expression for the bucket name for instance:
#[json: TopKey/BucketName]
From experience this has worked with JSON.
However when I run this, here is what I get:
Message : Failed to invoke getObjectContent. Message payload is of type: JsonData
Code : MULE_ERROR-29999
Failed to invoke getObjectContent. Message payload is of type: JsonData (org.mule.api.MessagingException)
org.mule.module.s3.processors.GetObjectContentMessageProcessor:177 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/MessagingException.html)
Is there a way I can use my JsonData object and pull information from it, or do I have to convert it back to something else before passing it on to the Amazon S3 component?
Thanks,
After trying a little more to play with my expression, I figured out I can just access elements the way I do it in my Java component already:
#[payload.get("TopKey").get("BucketName").getTextValue()]
and I have my BucketName!
Remove the empty space from your expression: #[json:TopKey/BucketName]
You can set the "Return Class" to java.util.Map in the "JSON to Object" processor, you can then access the value via #[payload.TopKey.BucketName]

Deserialize JSON containing an anonymous function using .net

I am getting a .net run-time error when attempting to desrialize a JSON string that contains an anonymous function:
Invalid JSON primitive: function.
JSON string itself looks like this:
{
Action: "fadeIn",
Callback: function(){doSomething();}
}
This makes me wonder if it is allowed to have anonymous functions in JSON strings that are to be serialized in .net. More specfically I can only use the .net frameworks's own JavaScriptSerializer class for deserialization. Can anyone confirm this, or have a solution?
JSON is a data representation protocol, and as such it can only be used to represent data, not behavior (which is what functions are). As your deserializer told you, what you have is not valid JSON (it's a valid JavaScript object, though, which causes some confusion). Check the JSON spec for more details on this format.
So to your question - no, you cannot deserialize JSON containing function, because it's not JSON in the first place.