In my ReactJS app, I want to validate a JSON object coming from API. I have the valid JSON schema and I want to make sure the coming object is in the correct structure before passing it.
Is there any React plugin which I can use for this.
If you want to draw the UI based on the json object after schema validation, then react-json-schema-form is your friend
Related
I'm building a REST API in JAVA and C# and I was wondering about the way I should pass data to those services.
What I'm familiar with as the right way is to send JSON object as the data in the POST body:
{name:'Dor'}
but I can also pass a string and parse the JSON in my service:
'{name:'Dor'}'
What is the preferable way from performance factor? or any other factors?
Basically, if you need to send the json data across via jquery, then we need to use stringify, else the data would be serialized into to key=value pair.
So, you cannot send the json object directly via jquery ajax method.
How it works behind the hood:
In $.ajax function, if we provide data as
data :{key1:"value1", key2:"value2"}
is serialized to key1=value1&key2=value2
if we provide data as
data :'{key1:"value1", key2:"value2"}' or JSON.stringify({key1:"value1", key2:"value2"})
is sent as {key1:"value1", key2:"value2"}
So, what we can conclude is that, we cannot pass json object directly via jquery, we can send only json string. Hope this clarifies everyone.
I have an instance where i need to validate an uploaded JSON file in the client side (i.e angularJS).
When a user uploads a JSON file. I need to validate the fields in the JSON, like
{"name":"Rohith"}
If this JSON is uploaded then I will have a schema such as
{"field":"name", "type":"String"}
I saw it can be done by ajv. But did not find any suitable examples with angularjs. Is there any other plugin which can do this?
Hi I am new to Java and not sure how to proceed (kindly ignore any typos or my language). Can somebody help me out (just the Idea/how to proceed, dont need any sample code). I am trying to create a Restful Json webservice (using Spring MVC).
The webservice that I am trying to create is kind of a wrapper for an existing XML based restful webservice.
The Idea is to have one common platform, since all other existing services are exposed as as JSON services.
My job is to fetch the XML transform it into a Json, but the tricky part is The Json schema is a superset of the XML schema (I mean it contains more elements that get filled with some default values).
Please let me know if you need more info.
Thanks in advance.
One way to do it would be to use Jaxb to transform the the incoming XML to Java Objects. Build your Jaxb objects in a way that it contains all the elements, the one with default values and the elements in the incoming XML.
Ones the XMl is converted into Jaxb you can use org.springframework.http.converter.json.MappingJacksonHttpMessageConverter message converter to convert your Jaxb object to Json string.
In my GWT project I need to process json data retrieved from a database via PHP. I have seen the Google examples using JavaScriptObject overlay classes. What I don't understand is why this seems to be the prefered method of processing the json data. Why shouldn't I use all native Java code to pull in the data?
Think about it the other way around: what does it mean to use POJOs? (or native Java classes as you name them)
You have to:
parse the JSON into some Java-accessible structure (e.g. com.google.gwt.json.client.JSONObject, or elemental.json.JsonObject)
create POJOs
fill the POJOs with the data from the parsed JSON structure
now you can forget the parsed JSON structure from step 1
On the other hand, with JavaScriptObject, you use JsonUtil.safeEval and TA-DA! you get your JSON parsed right into a typed Java object!
Now, to deal with JSON, there's also AutoBeans.
Choose your poison.
I basically have the following flow:
XML -> JSON -> Spring MVC -> jsp page, which is displayed as a table with editable fields.
How do make is so that when i edit a field value it correct updates the Json Object?
I have used some nasty hacking at the moment, as i know (testing) the values/object I am going to get, so im just parsing the JSON string in javascript and sending that back.
So i can then just convert the json object (with new values) and post it back.
Cheers.
You could use the serialize method from prototypejs.
http://www.prototypejs.org/api/form/serialize
just by calling .serialize() you'll be able to get the updated object.