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 3 years ago.
Improve this question
I'm getting one error in my code, Please suggest.
Google tool gives:
Syntax error: value, object or array expected.
JASON=LD Playground gives:
JSON markup - SyntaxError: JSON Parse error: Unrecognized token '<'
The latter error is due the fact that you left some HTML part inside the JSON validator text box (<script... is an HTML tag, it's not part of JSON).
The former error is due the fact that sometimes your JSON is using wrong double quotes symbols. Please note that double quotes can appear as:
" U+0022 QUOTATION MARK
“ U+201C LEFT DOUBLE QUOTATION MARK
” U+201D RIGHT DOUBLE QUOTATION MARK
Only the first symbol (that is the one that is present in almost all keyboards) is valid in JSON.
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 months ago.
Improve this question
I have a data as follows;
12432,20230
I want to remove the comma and replace it with space and want the output as follows;
12432 20230
I used the following code;
sed ’s/,/ /g’ file.csv > file.geno
but it gives error as;
sed: -e expression #1, char 1: unknown command: `�'
Your code is using "smart quotes", ’, instead of single quotes, ', just fix that and your syntax error will go away, i.e. instead of:
sed ’s/,/ /g’ file.csv > file.geno
use:
sed 's/,/ /g' file.csv > file.geno
You don't need the g at the end btw since you only have 1 comma in your input.
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 7 months ago.
Improve this question
Either using unicode or html won't work in the subject line, but this did: =?utf-8?B?4pyF?= I tried to look for a unicode to utf-8 decoder but none is returning anything like it.
The subject is encoded per RFC2047. In a netshell, an encoded word is:
encoded-word = "=?" charset "?" encoding "?" encoded-text "?="
charset is utf-8, encoding is B (per spec Base64 encoding), and encoded-text is 4pyF.
With Python we can generate and verify this:
>>> from email.header import Header
>>> h = Header('✅','utf-8')
>>> h.encode()
'=?utf-8?b?4pyF?='
>>> import base64
>>> base64.b64decode(b'4pyF').decode('utf-8')
'✅'
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
To change the md5 checksum of a json file, I am using the following filter in my httpd.conf:
ExtFilterDefine jsonfilter mode=output intype=application/json cmd="/usr/bin/perl -pe 'END { unless (-f q{/tmp/md5_filter.tmp}) { print qq(\\n\,\"STRING\"\: \") . time() . qq(\x0D\"\\n) }'"
But after the filter run, I receive an error, probally because the new string / timestamp get added after the last bracket } and leads to an unvalid json format:
SyntaxError: JSON.parse: unexpected non-whitespace character after JSON data at line 224 column 2 of the JSON data
Does someone know how to get this run correctly? Just to be sure: I just want to change the output of the file, before it gets response to the client browser. I don't want to change the original file itself. This should be untouched.
probally because the new string / timestamp get added after the last bracket } and leads to an unvalid json format
I don't know any details of the environment that you're working in, but I suspect that your suspicion is correct here.
You could try to fix your string-manipulating solution (perhaps by working out when you're processing the final line of the input and then printing your addition before printing the closing brace. But the best solution is to gather the input into a single string and then process it using a JSON parser.
Something like this (untested):
perl -MJSON -ne '$json .= $_; END { my $data = decode_json($json); $data->{STRING} = time; print encode_json($data);'
Update: To explain the various parts of my code.
-MJSON - loads the JSON module
-ne - n iterates over the input (putting each line, in turn, into $_); e executes code from the command line
$json .= $_ - this is run for every line of the input. It just takes each line and gathers them all together in a variable called $json
END { ... } - this block of code is only run once - after the input has all been read
my $data = decode_json($json) - takes the JSON text string (now stored in $json) and decodes it into a Perl data structure. That data structure is stored in $data
$data->{STRING} = time - adds another key/value pair to the data structure
print encode_json($data) - encodes the altered data structure back into a JSON string and prints that string to STDOUT
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
I have a script called import.rb which will import json content from url to drafts directory.
require 'fileutils'
require 'json'
# Load JSON data from source
# (Assuming the data source is a json file on your file system)
data = JSON.parse('https://script.google.com/macros/s/AKfycbyHFt1Yz96q91-D6eP4uWtRCcF_lzG2WM-sjrpZIr3s02HrICBQ/exec')
# Proceed to create post files if the value array is not empty
array = data["user"]
if array && !array.empty?
# create the `_drafts` directory if it doesn't exist already
drafts_dir = File.expand_path('./_drafts', __dir__)
FileUtils.mkdir_p(posts_dir) unless Dir.exist?(drafts_dir)
# iterate through the array and generate draft-files for each entry
# where entry.first will be the "content" and entry.last the "title"
array.each do |entry|
File.open(File.join(drafts_dir, entry.last), 'wb') do |draft|
draft.puts("---\n---\n\n#{entry.first}"
end
end
end
When I run ruby _scripts/import.rb I get _scripts/import.rb:20: syntax error, unexpected keyword_end, expecting ')'
end error. I changed line from recommended form to data = JSON.parse('https://script.google.com/macros/s/AKfycbyHFt1Yz96q91-D6eP4uWtRCcF_lzG2WM-sjrpZIr3s02HrICBQ/exec'). Original was data = JSON.parse(File.read(your_json_source.json)). Please assist me.
The problem is lacking ) at the end of 19 line:
...
array.each do |entry|
File.open(File.join(drafts_dir, entry.last), 'wb') do |draft|
draft.puts("---\n---\n\n#{entry.first}")
end
end
it should resolve the issue :)
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 5 years ago.
Improve this question
I have to store data containing tabulations in a file. I would like to use .TSV files (Tab-Separated File).
Here is an example of data (I manually escaped tabs and carriage return for the example):
Computation Display
0 for (int i=0;i<10;i++)\n\tx*=3; printf ("<b>éàè'"</b>");
1 float pi=3.1415; printf("%d %f",x,xf);
Is there a proper way to escape tabs? Should I use \t, should I use quotes or double quotes?
The abbreviation CSV means "Comma Separated Values", but in practice, this abbreviation is used for all files containing values that are separated by some separator-character. That's why spreadsheet applications like Open Office Calc or Microsoft Excel open up a dialog window letting you configure the separator and quoting character when you attempt to open a file with the file-extension .csv.
If your question is how the separator-character can be part of a value of a CSV file, the most common way is quoting the values. Here is in example of the quoting being done with the values
a,b
c"d
e
with , as the separator character and " as the quoting character
"a,b","c""d", e
The second way of quoting is the way Excel does it, you can also see variants where the quoting is done in the same way as the first example.
There are libraries out there that do the parsing and creation of CSV files for you. We "here" use the Ostermiller CSV library (there might be better ones nowerday but it does its job so there was no need to change the library after we introduced it "here" 10 years ago.