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
Related
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 1 year ago.
Improve this question
DTD and XML Schema are often used to define tags and attributes the should be used to properly write an XML files. Using them, it is thus possible to validate the content of XML files not just against the strict XML language syntax, but also looking at the content of each tag.
Is there an equivalent to this for other languages like JSON and YAML?
JSON has a schema language, as already stated in the comment (http://json-schema.org). JSON schema does allow validation of values as well as tags. It's not as mature as XML Schema, and in my own (subjective) opinion it is not as rigorously specified.
Apparently, JSON schema can also be used to describe YAML documents. See YAML Schema Validation?.
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 7 years ago.
Improve this question
Please help me decide between the following formats for storing articles on a server:
XML
JSON
YAML
CSV
There are too many and I don't have the knowledge to choose. I am looking for objective criteria, not subjective opinions.
The articles may contain a short title, some paragraphs and images.
XML vs JSON vs YAML vs CSV
Here are some considerations you might use to guide your decision:
Choose XML if
You have to represent mixed content (tags mixed within text). [This would appear to be a major concern in your case. You might even consider HTML for this reason.]
There's already an industry standard XSD to follow.
You need to transform the data to another XML/HTML format. (XSLT is great for transformations.)
Choose JSON if
You have to represent data records, and a closer fit to JavaScript is valuable to your team or your community.
Choose YAML if
You have to represent data records, and you value some additional features missing from JSON: comments, strings without quotes, order-preserving maps, and extensible data types.
Choose CSV if
You have to represent data records, and you value ease of import/export with databases and spreadsheets.
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.
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.
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.