What is this JSON variation? [closed] - json

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have got some data that seems to be JSON but with data types and string lengths.
Data=a2:{i:0;a:2:{s:4:"user";s:7:"example";s:5:"email";s:19:"example#example.com";}i:1;a:2:{s:4:"user";s:8:"example2";s:5:"email";s:20:"example2#example.com";}}

The only connection it probably has to json is that it uses things like {, : etc.
This looks like a serialized string: http://en.wikipedia.org/wiki/Serialization
Depending on what is going to happen with it, where it came from, etc you can find out what it was / needs to be. It could be a simple object where your language's "serialize" function was called on, and then made into a literal string to feed to some database
See for an example this php function: http://www.php.net/manual/en/function.serialize.php
What it could be is that you have an app in PHP that reads serialized data from a database, and another app (like java) is trying to (pre-?) fill this database with some object. now java doesn't know how to serialize for php, but it can have a copy/pasted piece of text by a developer in it.
I'm not saying that it is exactly that, but as it kinda looks like php serialized code but the assignment doesn't, it might be some form of combination of the two. Impossible to say without more info.

This is not JSON. JSON has no variations. This appears to be a serialized string. This is pretty close to how PHP serializes, but the start should be a:2 instead of Data=a2. It could be serialized by some other language, though. If you know the source language, it should provide some method for deserializing it into data structures of that language.

Related

How to convert python dict to json [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I am trying to convert python dictionary to JSON
Example:
dict = {'key1':'value1','key2':'value2'}
Tried with json.dumps but I didn't get the expected output.
Example:
json.dumps(dict)
Output:
'{"key1":"value1","key2":"value2"}'
Expected output:
{"key1":"value1","key2":"value2"}
How to remove that single quotes? or please suggestion any other possibilitys
I am new to coding and sorry for my english
Thank you
just add this line to your code
dict = json.loads(json.dumps(dict))
print(type(dict)) #class,dict
now this will be a dictionery
I am not completely understand What is JSON and its format that is my problem.
JSON (JavaScript Object Notation) is a lightweight data-interchange format. It is easy for humans to read and write. It is easy for machines to parse and generate. JSON is a text format that is completely language independent but uses conventions that are familiar to programmers of the C-family of languages, including C, C++, C#, Java, JavaScript, Perl, Python, and many others.
I refer this
The valid JSON string is '{"key1":"value1","key2":"value2"}'
Thank you

Making an API throw HTTP errors or return empty objects [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 3 years ago.
Improve this question
Is is more elegant to make a JSON-API return plain HTTP error codes or empty arrays/objects as JSON to a frontend?
Example:
1. Frontend legitimately requests a user profile.
2. The custom permission system implementation determines that this user is not permitted to access the profile and returns 403 (backend-side).
3. Frontend uses a try/catch-like syntax in various places just to interpret the error code.
The used frameworks are ASP.NET Core and Angular (to specify the context).
The answer depends on the error and status code. In general, you should not return things like an empty array or empty object, unless that's literally the result. For example, if someone requests a list of Foos for example, and there's literally none, then it would be appropriate to return an empty array. That would be a successful 200, though.
For something like a 403, you should either return no body or if you do return a body, it should be an error object, such as a problem details response - not empty.
A 403 is a bit of a special case, as the status code itself is generally descriptive enough, and there may not even be additional information to add. In other words, the client is forbidden; it's generally not important why, and there's generally no way to correct it, assuming they've authenticated. In cases where there's no real way to recover or the reasons for the result are unimportant or obvious, then you can return no response body at all. In all other cases, you should return "something", even if it's just a simple string message, in order to help the client understand what happened.
Empty arrays/objects should be reserved for when the actual result is an empty array/object, and that's all.

Why is JSON used in MongoDB? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Why is JSON-formatted data stored in MongoDB? Is that the only format supported in MongoDB? What are the advantages of using JSON for storing records in MongoDB? What is the benefit of using JSON in Mong DB over other formats?
Actually Mongo uses BSON, that could represent the same things that JSON, but with less space. "JSON" (that is like the representation for human beings) have some properties useful in a NoSQL database:
No need for a fixed schema. You could just add whatever you want and it will be correct JSON.
There are parsers available for almost any programming language out there.
The format is programmer friendly, not like some alternatives... I'm looking at you, XML ¬¬.
Mongo needs to understand the data, without forcing a "collection schema". You don't need information about the object to reason about it, if it uses JSON. For example, you could get the "title" or "age" for any JSON document, just find that field. With other formats (eg. protocol buffers) thats not possible. At least without a lot of code...
(Added) Because Mongo is a database they want to do queries fast. BSON/JSON is a format that can meet that requirement AND the others at the same time (easily implementable, allow reflectioning about data, parsing speed, no fixed schema, etc).
(Added) Mongo reuses a Javascript engine for their queries, so it have all the sense in the world to reuse JSON for object representation. BSON is a more compact representation for that format.

json tree file,url to csv file using python [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I am trying to convert a number of .json files to .csv's using Python 2.7
Is there any general way to convert a json file to a csv?
PS: I saw various similar solutions on stackoverflow.com but they were very specific
to json tree and doesn't work if the tree structure changes. I am new to this site and am sorry for my bad english and reposting ty
The basic thing to understand is that json and csv files are extremely different on a very fundamental level.
A csv file is just a series of value separated by commas, this is useful for defining data like those in relational databases where you have exactly the same fields repeated for a large number of objects.
A json file has structure to it, there is no straightforward way to represent any kind of tree structure in a csv. You can have various types of foreign key relationships, but when it comes right down to it, trees don't make any sense in a csv file.
My advice to you would be to reconsider using a csv or post your specific example because for the vast majority of cases, there is no sensible way to convert a json document into a csv.

Best Practice for Subset of Business Object Fields Structure? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
If I have a business object with 50 fields, and I need to populate something like a drop down list or gridview with only 3 fields from the business object to allow quick browsing.
Is it best practice to load the fully populated BO then just grab the few required fields in your presentation layer ?
It seems inefficient to populate a collection of Bo's that size but the only other ways would seem to be to return partially populated BO's with just the fields you need for a particular UI which would be hard to manage if you have alot of similar UI requirements, or make a baseclass like MyBusinessObjectHeader that contains the fields then make MyBusinessObject inherit it and implement the rest of the fields but this would tie it your UI too much it seems.
Whats the best practice for this type of situation ?
I make a separate readonly list of readonly digest objects (or structs) that are lightweight and cannot be manipulated. The collection can be customized for whatever needs you might have as normal. Retrieval of a full object can be used by passing a "digest" object to a type conversion, or factory or constructor - whatever techniques you are using.
Note that this is an optimization which only happens when a collection of full-blown objects is simply getting too slow. It can easily be created at that point. Generally such classes are not created until necessary.
There are a lot of frameworks out there that do this sort of o/r mapping you're talking about.
You're trading a little more overhead for ease of use and robust configuration.
See Hibernate or NHibernate if you're using .net.