質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
ファイル

ファイルとは、文字列に基づいた名前又はパスからアクセスすることができる、任意の情報のブロック又は情報を格納するためのリソースです。

JSON

JSON(JavaScript Object Notation)は軽量なデータ記述言語の1つである。構文はJavaScriptをベースとしていますが、JavaScriptに限定されたものではなく、様々なソフトウェアやプログラミング言語間におけるデータの受け渡しが行えるように設計されています。

機械学習

機械学習は、データからパターンを自動的に発見し、そこから知能的な判断を下すためのコンピューターアルゴリズムを指します。人工知能における課題のひとつです。

置換

置換とは文字列中の特定の文字に対して、別の文字列に置き換えることを指します。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

Q&A

2回答

1819閲覧

jsonファイルシングルクォーテーションをダブルクォーテーションに置換したい

Kokku

総合スコア39

ファイル

ファイルとは、文字列に基づいた名前又はパスからアクセスすることができる、任意の情報のブロック又は情報を格納するためのリソースです。

JSON

JSON(JavaScript Object Notation)は軽量なデータ記述言語の1つである。構文はJavaScriptをベースとしていますが、JavaScriptに限定されたものではなく、様々なソフトウェアやプログラミング言語間におけるデータの受け渡しが行えるように設計されています。

機械学習

機械学習は、データからパターンを自動的に発見し、そこから知能的な判断を下すためのコンピューターアルゴリズムを指します。人工知能における課題のひとつです。

置換

置換とは文字列中の特定の文字に対して、別の文字列に置き換えることを指します。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

0グッド

0クリップ

投稿2021/03/31 14:52

機械学習用にjsonファイルを読み込もうとしたのですが、シングルクォーテーションのせいでエラーが起こっているのでファイル内のシングルクォーテーションをダブルクォーテーションに置換するプログラムを書きたいです。

[{'face_token': '3d03eb39f7479435db8ce3eb171f47b6', 'face_rectangle': {'top': 64, 'left': 31, 'width': 214, 'height': 214}, 'landmark': {'contour_chin': {'x': 117, 'y': 273}, 'contour_left1': {'x': 33, 'y': 101}, 'contour_left2': {'x': 33, 'y': 124}, 'contour_left3': {'x': 35, 'y': 147}, 'contour_left4': {'x': 37, 'y': 169}, 'contour_left5': {'x': 42, 'y': 192}, 'contour_left6': {'x': 49, 'y': 213}, 'contour_left7': {'x': 61, 'y': 233}, 'contour_left8': {'x': 76, 'y': 250}, 'contour_left9': {'x': 93, 'y': 265}, 'contour_right1': {'x': 247, 'y': 107}, 'contour_right2': {'x': 246, 'y': 133}, 'contour_right3': {'x': 242, 'y': 159}, 'contour_right4': {'x': 238, 'y': 184}, 'contour_right5': {'x': 230, 'y': 209}, 'contour_right6': {'x': 215, 'y': 230}, 'contour_right7': {'x': 195, 'y': 247}, 'contour_right8': {'x': 171, 'y': 260}, 'contour_right9': {'x': 146, 'y': 271}, 'left_eye_bottom': {'x': 77, 'y': 107}, 'left_eye_center': {'x': 79, 'y': 101}, 'left_eye_left_corner': {'x': 57, 'y': 101}, 'left_eye_lower_left_quarter': {'x': 66, 'y': 104}, 'left_eye_lower_right_quarter': {'x': 89, 'y': 107}, 'left_eye_pupil': {'x': 79, 'y': 99}, 'left_eye_right_corner': {'x': 100, 'y': 107}, 'left_eye_top': {'x': 79, 'y': 92}, 'left_eye_upper_left_quarter': {'x': 67, 'y': 94}, 'left_eye_upper_right_quarter': {'x': 91, 'y': 97}, 'left_eyebrow_left_corner': {'x': 42, 'y': 80}, 'left_eyebrow_lower_left_quarter': {'x': 55, 'y': 76}, 'left_eyebrow_lower_middle': {'x': 69, 'y': 77}, 'left_eyebrow_lower_right_quarter': {'x': 83, 'y': 84}, 'left_eyebrow_right_corner': {'x': 99, 'y': 89}, 'left_eyebrow_upper_left_quarter': {'x': 54, 'y': 65}, 'left_eyebrow_upper_middle': {'x': 71, 'y': 65}, 'left_eyebrow_upper_right_quarter': {'x': 87, 'y': 74}, 'mouth_left_corner': {'x': 78, 'y': 189}, 'mouth_lower_lip_bottom': {'x': 124, 'y': 230}, 'mouth_lower_lip_left_contour1': {'x': 98, 'y': 208}, 'mouth_lower_lip_left_contour2': {'x': 87, 'y': 208}, 'mouth_lower_lip_left_contour3': {'x': 101, 'y': 223}, 'mouth_lower_lip_right_contour1': {'x': 149, 'y': 210}, 'mouth_lower_lip_right_contour2': {'x': 159, 'y': 211}, 'mouth_lower_lip_right_contour3': {'x': 145, 'y': 224}, 'mouth_lower_lip_top': {'x': 124, 'y': 217}, 'mouth_right_corner': {'x': 168, 'y': 193}, 'mouth_upper_lip_bottom': {'x': 125, 'y': 198}, 'mouth_upper_lip_left_contour1': {'x': 117, 'y': 191}, 'mouth_upper_lip_left_contour2': {'x': 97, 'y': 189}, 'mouth_upper_lip_left_contour3': {'x': 102, 'y': 194}, 'mouth_upper_lip_right_contour1': {'x': 133, 'y': 191}, 'mouth_upper_lip_right_contour2': {'x': 151, 'y': 191}, 'mouth_upper_lip_right_contour3': {'x': 147, 'y': 195}, 'mouth_upper_lip_top': {'x': 125, 'y': 193}, 'nose_contour_left1': {'x': 109, 'y': 104}, 'nose_contour_left2': {'x': 100, 'y': 141}, 'nose_contour_left3': {'x': 105, 'y': 170}, 'nose_contour_lower_middle': {'x': 123, 'y': 178}, 'nose_contour_right1': {'x': 140, 'y': 105}, 'nose_contour_right2': {'x': 148, 'y': 144}, 'nose_contour_right3': {'x': 141, 'y': 172}, 'nose_left': {'x': 91, 'y': 158}, 'nose_right': {'x': 155, 'y': 162}, 'nose_tip': {'x': 124, 'y': 164}, 'right_eye_bottom': {'x': 173, 'y': 109}, 'right_eye_center': {'x': 172, 'y': 104}, 'right_eye_left_corner': {'x': 152, 'y': 106}, 'right_eye_lower_left_quarter': {'x': 162, 'y': 108}, 'right_eye_lower_right_quarter': {'x': 184, 'y': 108}, 'right_eye_pupil': {'x': 172, 'y': 102}, 'right_eye_right_corner': {'x': 193, 'y': 105}, 'right_eye_top': {'x': 172, 'y': 95}, 'right_eye_upper_left_quarter': {'x': 161, 'y': 98}, 'right_eye_upper_right_quarter': {'x': 183, 'y': 98}, 'right_eyebrow_left_corner': {'x': 150, 'y': 92}, 'right_eyebrow_lower_left_quarter': {'x': 169, 'y': 90}, 'right_eyebrow_lower_middle': {'x': 186, 'y': 86}, 'right_eyebrow_lower_right_quarter': {'x': 202, 'y': 84}, 'right_eyebrow_right_corner': {'x': 216, 'y': 87}, 'right_eyebrow_upper_left_quarter': {'x': 166, 'y': 79}, 'right_eyebrow_upper_middle': {'x': 184, 'y': 72}, 'right_eyebrow_upper_right_quarter': {'x': 204, 'y': 72}}, 'attributes': {'gender': {'value': 'Male'}, 'age': {'value': 26}, 'emotion': {'anger': 98.934, 'disgust': 1.06, 'fear': 0.002, 'happiness': 0.001, 'neutral': 0.001, 'sadness': 0.001, 'surprise': 0.002}}}, . . . .
json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 1 column 3 (char 2)

ネットで検索してみても具体的な方法が書かれてあるサイトがなかったので質問させていただきました。

何か解決方法があれば教えていただきたいです。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

quickquip

2021/04/01 00:58

シングルクォーテーションが使われているなら「それはJSON形式ではない」ので、JSON形式でデータを入手できるようにするにはどうするか、という方に労力を使う方が健全な気がします。 データの由来を質問に書いた方がいいんじゃないでしょうか。
guest

回答2

0

プログラミングが出来ないのであれば、エディタで置換すれば良いのではないでしょうか。

投稿2021/03/31 15:07

otn

総合スコア84533

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

Kokku

2021/03/31 15:34

これが200行くらいあるファイルなのでプログラミングで処理する方法はあればなと思い投稿しました
otn

2021/03/31 15:42

もしかして、エディタお使い方も良くわからない状態ですか?
guest

0

そのデータを

#!/usr/bin/env python3 x=[{'face_token': '3d03eb39f7479435db8ce3eb171f47b6', 'face_rectangle': {'top': 64, 'left': 31, 'width': 214, 'height': ..... import json print(json.dumps(x))

などとすれば json 出力できるかもしれませんが、json じゃなくて jsonl だったりすると難しいかもしれません。

エディタで ' を " に一括置換してみるのは悪くない手だと思います。

投稿2021/03/31 16:56

68user

総合スコア2005

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問