0

I have this Json in a file:

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

I wrote this script which should print all of the json text:

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)

It doesn't work, can you help me? This is what happens:

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

json.decoder.JSONDecodeError: Extra data:

1
  • 1
    You have a trailing comma in your JSON, it's not valid. Commented Oct 17, 2018 at 15:58

1 Answer 1

1

As stated by @dwjv, your json file is not valid:

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

Just remove it and you should be good to go.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.