How to write description document for JSON file? - json

I want to write a description document for my JSON files. I used to write it for database. It has ER Diagram and Data Dictionary. But when it comes to JSON file, are there any diagrams that can be used to describe JSON file that can be read easily?

Try out http://jsonviewer.stack.hu/. For a json string like this,
{
"address": {
"streetAddress": "21 2nd Street",
"city": "New York"
},
"phoneNumber": [
{
"type": "home",
"number": "212 555-1234"
}
]
}
It produces an output like,

Related

How to import an image with the local path listed in a json file?

I am having a problem setting up a an image in json file with local path.
I have a folder named Images and a Data json file. I want to json file to hold my pictures in json locally.
{
"name": "John",
"id": "001",
"price": "$995",
"image": "./Images/picture1.jpg"
},
{
"name": "John",
"id": "001",
"price": "$995",
"image": "./Images/picture2.jpg"
},
{
"name": "John",
"id": "001",
"price": "$995",
"image": "./Images/picture1.jpg"
},
{
"name": "John",
"id": "001",
"price": "$995",
"image": "./Images/picture2.jpg"
},
Please tell my why this does not work.
JSON files only contain strings without any linking. So "./Images/picture2.jpg" is just a string without any meaning for your editor.
Some apps or editors might present some eye candy features, like maybe what you are looking for. But this is totally an option of the editor and not something of JSON itself.
JSON are plain text files that store key, values.
I hope it helps

Azure Logic Apps - Map Json to Json with Liquid flatten array

Any help would be much appreciated. What I am trying to achieve is to request a record from Dynamics 365(cloud) to an on-premise system (exposed by mulesoft) I have decided to use Azure logic apps to do the integration and to use Liquid to do the mapping, however I am battling to flatten the array with liquid, I'm getting a JSON payload from the on-premise system which I need to transform readily to load into dynamics 365, what I am getting is something like the following:
{
"person": {
"firstname": " Fred",
"surname" : "Smith",
"age": 27,
"phoneno":"123456789",
"addresses": [
{
"address": {
"AddressLine1":"1 milky way",
"AddressLine2":"galaxy cresent",
"city": "tempest",
"state": "Idiho",
"postcode": "12345"
}
},
{
"address": {
"AddressLine1":"52 Saturn Drive",
"AddressLine2":"Wharfridge",
"city": "tempest",
"state": "Idiho",
"postcode": "12345"
}
}
]
}
}
and what I need is to flatten the array into the root node like this:
{
"person": {
"firstname": " Fred",
"surname" : "Smith",
"age": 27,
"phoneno":"123456789",
"addr1_AddressLine1":"1 milky way",
"addr1_AddressLine2":"galaxy cresent",
"addr1_city": "tempest",
"addr1_state": "Idiho",
"addr1_postcode": "12345",
"addr2_AddressLine1":"52 Saturn Drive",
"addr2_AddressLine2":"Wharfridge",
"addr2_city": "tempest",
"addr2_state": "Idiho",
"addr2_postcode": "12345"
}
}
If there any other solutions\ideas, i am all ears.
Thanks in advance for your help
Paul
So i found a solution or rather a work around, for some reason the liquid connector in logic apps does not support the "increment" tag, this was causing my issue. i was able to evaluate a property form the input json to decide where my fields would reside. but thanks for

How to store a Json File Using Lift Mapper in MySql

I am new to Liftweb. I want to Store a Json File in Mysql database using Lift Mapper
My Json File Like Below:-
[
{
"name": "Root Category",
"Id": "1",
"dispName": "",
"childs": [
{
"name": "Sub Category",
"Id": "",
"dispName": "",
"childs": [
{
"name": "Spec1",
"Id": "",
"dispName": "",
"childs": []
}
]
}
]
},
{
"name": "Root Category",
"Id": "",
"dispName": "",
"childs": [
{
"name": "Sub Category",
"Id": "",
"dispName": "",
"childs": [
{
"name": "Spec1",
"Id": "",
"dispName": "",
"childs": []
}
]
}
]
}
]
Is it Possible to store a Json File in Lift Mapper .Please give me Suggestions. It will be great if some one provide any sample
Best Regards
GSY
At the moment there is no good support for storing JSON in MySQL. I mean it's not going to provide capabilities MongoDB provides for example. However there are some JSON processing functions provided by community if you want. Given all that you can store it in VARCHAR. TEXT or BLOB field type as simple text. Here is a Mapper example:
import net.liftweb.mapper._
import net.liftweb.common._
class SomeDbClass extends LongKeyedMapper[SomeDbClass] with IdPK {
def getSingleton = SomeDbClass
// set limit of chars - can be used in `validate()`
object quota_type extends MappedString(this, 1024)
}
object SomeDbClass extends SomeDbClass with LongKeyedMetaMapper[SomeDbClass]
For one of my projects I store JSON as a string in Postgres similarly because I just need to read and write it without having to parse it in DB and query by fields. Whenever I need efficient JSON storage with query and update support I use MongoDB with Record + ( Casbah or Rogue ).

How does one enforce HTTP responses as JSON messages?

I am quite new to json and webservices.
I have a question which might as well be a dumb one but I have not been able to find an answer.
Lets say I have a html form which performs a GET method on submission.
The server performs an HTTP response.
How does one make sure that the content(body) of the response is in JSON format?
-V
This is quite a vague question as I don't know what your server is doing and replying (obviously it should be in the JSON format response) but you should also include a Content-type HTTP header as shown below so the browser knows it is receiving JSON:
Content-type: application/json
Your JSON response should look like this (taken from Wikipedia):
{
"firstName": "John",
"lastName": "Smith",
"age": 25,
"address": {
"streetAddress": "21 2nd Street",
"city": "New York",
"state": "NY",
"postalCode": 10021
},
"phoneNumbers": [
{
"type": "home",
"number": "212 555-1234"
},
{
"type": "fax",
"number": "646 555-4567"
}
]
}
data=response_from_the_page;
try {
json = $.parseJSON(data);
} catch (e) {
// not json
}

JSON Array Question

How to use jsp to get json resulting in folowing format ?
{
"firstName": "John",
"lastName": "Smith",
"address": {
"streetAddress": "21 2nd Street",
"city": "New York",
"state": "NY",
"postalCode": 10021
},
"phoneNumbers": [
"212 732-1234",
"646 123-4567"
]
}
You can use different libraries to convert from diferent java objects to JSON
For example the library json-simple http://code.google.com/p/json-simple/
In the json-simple page you can see some examples of encoding,decoding, and JSP & AJAX with these library.
Structure a Java object in a similar fashion and then use a serialization mechanism
such as json-simple or xstream with Json Driver
for instance
new XStream(new JettisonMappedXmlDriver());
xstream.toXML(object);
Got it.
Create JSONObject.
Create JSONArray.
Merge.
Thanks guy. Appreciate.