gpt4 book ai didi

python - Python-将json文件插入elasticsearch

转载 作者:行者123 更新时间:2023-12-03 01:35:38 28 4
gpt4 key购买 nike

我在文件中有这个Json:

{
"name": "Huntington Beach",
"beach": "50 N of Santa Ana River",
"SampleDate": "02/01/18",
"ParameterCode": "Enterococcus",
"Qualifier": "=",
"Result": "8",
"Units": "CFU/100ml"
},
我编写了此脚本,该脚本应打印所有json文本:
from pprint import pprint
import requests
import urllib
import json
from elasticsearch import Elasticsearch
from elasticsearch import helpers
from elasticsearch.serializer import JSONSerializer
import os,sys

directory = '/home/Documents/folder/myfile.json'

es = Elasticsearch([{'host': '', 'port': }])

with open(directory, 'r', encoding='utf-8') as f:
data=json.loads(f.read())
pprint(data)

es.index(index='my_index', doc_type='doc', body=data)
它不起作用,您能帮我吗?这是发生了什么:

raise JSONDecodeError("Extra data", s, end)

json.decoder.JSONDecodeError: Extra data:

最佳答案

如@dwjv所述,您的json文件无效:

{
"name": "Huntington Beach",
"beach": "50 N of Santa Ana River",
"SampleDate": "02/01/18",
"ParameterCode": "Enterococcus",
"Qualifier": "=",
"Result": "8",
"Units": "CFU/100ml"
}, <---trailing comma

只需将其删除,您应该会很好。

关于python - Python-将json文件插入elasticsearch,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52858930/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com