Questions tagged [parsing]

Parsing refers to breaking an artifact into its constituent elements and capturing the relationship between those elements. This tag isn't for questions about the self hosted Parse Platform (use the [parse-platform] tag) or parse errors in a particular programming language (use the appropriate language tag instead).

Parsing refers to the action by software of breaking an artifact into its constituent elements and capturing the relationship between those elements.

When the artifact is a stream of arbitrary text, parsing is often used to mean breaking the stream into constituent atoms (called words, tokens or lexemes).

When the artifact is a stream of natural language text, parsing is used to mean breaking the stream into natural language elements (words and punctuation) and discovering the structure of the text as phrases or sentences.

When the artifact is a stream of text corresponding to a computer language (or other formal language), parsing consists of applying any of a variety of parsing algorithms (ad hoc, recursive descent, LL, LR, Packrat, Earley or other) to the source text (often broken into lexemes by another lower level parser called a "lexer") to verify the validity of the source language, and often to construct a parse tree representing the grammar productions used to tile the text.

The term can be applied more generally to analyzing any complex structure such as a binary data file or a graph.

57220 questions
2709
votes
33 answers

How do I parse a string to a float or int?

How can I convert a str to float? "545.2222" → 545.2222 How can I convert a str to int? "31" → 31 For the reverse, see Convert integer to string in Python and Converting a float to a string without rounding it. Please instead use…
Tristan Havelick
  • 67,400
  • 20
  • 54
  • 64
1754
votes
16 answers

Parse JSON in JavaScript?

I want to parse a JSON string in JavaScript. The response is something like var response = '{"result":true,"count":1}'; How can I get the values result and count from this?
user605334
1504
votes
3 answers

Why can't Python parse this JSON data?

I have this JSON in a file: { "maps": [ { "id": "blabla", "iscategorical": "0" }, { "id": "blabla", "iscategorical": "0" } ], "masks": [ "id":…
michele
  • 26,348
  • 30
  • 111
  • 168
1486
votes
28 answers

Safely turning a JSON string into an object

Given a string of JSON data, how can I safely turn that string into a JavaScript object? Obviously I can do this unsafely with something like: var obj = eval("(" + json + ')'); but that leaves me vulnerable to the JSON string containing other code,…
Matt Sheppard
  • 116,545
  • 46
  • 111
  • 131
1309
votes
36 answers

How to parse JSON in Java

I have the following JSON text. How can I parse it to get the values of pageName, pagePic, post_id, etc.? { "pageInfo": { "pageName": "abc", "pagePic": "http://example.com/content.jpg" }, "posts": [ { "post_id":…
Muhammad Maqsoodur Rehman
  • 33,681
  • 34
  • 84
  • 124
1300
votes
24 answers

How to reformat JSON in Notepad++?

I need Notepad++ to take a json string from this {"menu": {"id": "file","value": "File","popup": {"menuitem": [{"value": "New", "onclick": "CreateNewDoc()"},{"value": "Open", "onclick": "OpenDoc()"},{"value": "Close", "onclick":…
Donny V.
  • 22,248
  • 13
  • 65
  • 79
1247
votes
46 answers

Parsing JSON with Unix tools

I'm trying to parse JSON returned from a curl request, like so: curl 'http://twitter.com/users/username.json' | sed -e 's/[{}]/''/g' | awk -v k="text" '{n=split($0,a,","); for (i=1; i<=n; i++) print a[i]}' The above splits the JSON into…
auser
  • 13,808
  • 4
  • 21
  • 15
1168
votes
12 answers

How to escape braces (curly brackets) in a format string in .NET

How can brackets be escaped in using string.Format? For example: String val = "1,2,3" String.Format(" foo {{0}}", val); This example doesn't throw an exception, but it outputs the string foo {0}. Is there a way to escape the brackets?
Pop Catalin
  • 61,751
  • 23
  • 87
  • 115
919
votes
26 answers

Identify if a string is a number

If I have these strings: "abc" = false "123" = true "ab2" = false Is there a command, like IsNumeric() or something else, that can identify if a string is a valid number?
Gold
  • 60,526
  • 100
  • 215
  • 315
766
votes
20 answers

PHP parse/syntax errors; and how to solve them

Everyone runs into syntax errors. Even experienced programmers make typos. For newcomers, it's just part of the learning process. However, it's often easy to interpret error messages such as: PHP Parse error: syntax error, unexpected '{' in…
mario
  • 144,265
  • 20
  • 237
  • 291
644
votes
35 answers

Parse (split) a string in C++ using string delimiter (standard C++)

I am parsing a string in C++ using the following: using namespace std; string parsed,input="text to be parsed"; stringstream input_stringstream(input); if (getline(input_stringstream,parsed,' ')) { // do some processing. } Parsing with a…
TheCrazyProgrammer
  • 7,918
  • 8
  • 25
  • 41
616
votes
13 answers

How can I extract audio from video with ffmpeg?

I tried the following command to extract audio from video: ffmpeg -i Sample.avi -vn -ar 44100 -ac 2 -ab 192k -f mp3 Sample.mp3 but I get the following output libavutil 50.15. 1 / 50.15. 1 libavcodec 52.72. 2 / 52.72. 2 libavformat 52.64. 2…
user1269669
  • 6,177
  • 3
  • 14
  • 5
550
votes
13 answers

Pandas read_csv: low_memory and dtype options

df = pd.read_csv('somefile.csv') ...gives an error: .../site-packages/pandas/io/parsers.py:1130: DtypeWarning: Columns (4,5,7,16) have mixed types. Specify dtype option on import or set low_memory=False. Why is the dtype option related to…
Josh
  • 11,979
  • 17
  • 60
  • 96
543
votes
21 answers

How to convert jsonString to JSONObject in Java

I have String variable called jsonString: {"phonetype":"N95","cat":"WP"} Now I want to convert it into JSON Object. I searched more on Google but didn't get any expected answers!
Mr. Sajid Shaikh
  • 7,051
  • 4
  • 21
  • 35
542
votes
22 answers

How to join multiple lines of filenames into one with custom delimiter

How do I join the result of ls -1 into a single line and delimit it with whatever I want?
JavaRocky
  • 19,203
  • 31
  • 89
  • 110
1
2 3
99 100